Matlab提取多个文件夹里同文件名csv文件

2024-11-29 15:05:01
推荐回答(1个)
回答1:

clc;clear all;
file = input('要处理的数据文件名:','s');
path = cd();
s1 = dir(path); 
[m,n]=size(s1);
for i = 3:m
   if s1(i).isdir
       s2 = dir([path '/' s1(i).name]);
       [p,q]=size(s2);
       for j = 3:p
           csvfilename = [path '\' s1(i).name '\' s2(j).name '\' file];
           fprintf('%s\n',csvfilename);
           [d1,Y]=textread(csvfilename,'%d%f%*[^\n]','delimiter',',');
           Y(find(d1<93000))=[]; %去掉093000之前的数据
           matfilename = [s2(j).name '.mat'];
           save(matfilename,'Y');
       end
   end
end

 

要处理的数据文件名:SH600000.CSV
D:\MATLAB\working\2013\201301\20130102\SH600000.CSV
D:\MATLAB\working\2013\201301\20130103\SH600000.CSV
D:\MATLAB\working\2013\201301\20130104\SH600000.CSV
D:\MATLAB\working\2013\201301\20130105\SH600000.CSV
D:\MATLAB\working\2013\201301\20130122\SH600000.CSV
D:\MATLAB\working\2013\201301\20130131\SH600000.CSV
D:\MATLAB\working\2013\201302\20130203\SH600000.CSV
D:\MATLAB\working\2013\201302\20130204\SH600000.CSV
D:\MATLAB\working\2013\201302\20130205\SH600000.CSV
D:\MATLAB\working\2013\201303\20130302\SH600000.CSV
D:\MATLAB\working\2013\201303\20130312\SH600000.CSV
D:\MATLAB\working\2013\201303\20130331\SH600000.CSV
D:\MATLAB\working\2013\201304\20130403\SH600000.CSV
D:\MATLAB\working\2013\201304\20130415\SH600000.CSV
D:\MATLAB\working\2013\201305\20130503\SH600000.CSV
D:\MATLAB\working\2013\201305\20130505\SH600000.CSV
D:\MATLAB\working\2013\201306\20130602\SH600000.CSV
D:\MATLAB\working\2013\201306\20130631\SH600000.CSV