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

补充读取xls 文件:

        xlsread('filename.xls','sheet1','J5:J275');

 

posted @ 2022-06-02 16:53  SusieSnail_SUN  阅读(3800)  评论(0编辑  收藏  举报