其他分享
首页 > 其他分享> > MATLAB 读取指定路径文件

MATLAB 读取指定路径文件

作者:互联网

clear all
close all
clc

%% 读取指定路径文件

file_path   = 'C:\Users\20220601_155213\198-1\';
file_name = '*.csv';
dirOfFile = dir([file_path, file_name]); 
numOfFiles = length(dirOfFile);

for aa_file = 1:numOfFiles 
file_name = dirOfFile(aa_file).name; 

  A = importdata([file_path, file_name]);
  data = A.data(:, 2);

  end     

file_path   = 'C:\Users\20220601_155213\198-1\';
file_name = '*.csv';
dirOfFile = dir([file_path, file_name]); 
numOfFiles = length(dirOfFile);  

data = [];

for aa_file = 1:numOfFiles 
    file_name = dirOfFile(aa_file).name; 
    filePath_name_whole = [file_path, file_name];
    data_ori_whole = readmatrix(filePath_name_whole);
    if ( 1 == isstruct(data_ori_whole) )
        data_ori_whole = data_ori_whole.data;
    end
    sizeBuff = size(data_ori_whole);
    row = sizeBuff(1);
    i_row = 1;
    
    fs = data_ori_whole(i_row, 2);    
    while(i_row <= row)
        if isnan(data_ori_whole(i_row, 1))
            data_ori_whole(i_row, :) = [];
            i_row = i_row - 1;
        else
            break;
        end
        i_row = i_row + 1;
    end
    data = data_ori_whole(:, 2); 
    
end 

 两种处理方式:

        1.   importdata

        2.   readmatrix

标签:name,whole,路径,dirOfFile,MATLAB,file,ori,data,读取
来源: https://www.cnblogs.com/susiesnai-sun/p/16338333.html