这里通过循环来写读取文件函数。
function ReadFile(MainPath,FileType,FileLayer)
%%%%%%%%%%%%%%
%MainPath为主路径,FileType为需要读取的文件类型,FileLayer为文件类型在哪一层文件下
cd(MainPath);
if(FileLay>=0)
PathFileFormation=dir('*.');
PathNumber=numel(PathFileFormation);
for LoopPathNumer=3:PathNumber
Path=fullfile(MainPath,PathFileFormation(LoopPathNumber).name);
ReadFile(Path,FileType,FileLayer-1)
end
else
PathFileFormation=dir('FileType');
PathNumber=numel(PathFileFormation);
for LoopPathNumer=3:PathNumber
Path=fullfile(MainPath,PathFileFormation(LoopPathNumber).name)
end
end