Matlab code for accessing different folder data
조회 수: 6 (최근 30일)
이전 댓글 표시
I have 20 excel file of data in 20 different folder. Want to access them all in one matlab code for plot. And can't put all in same folder. Actually all have same name. Need help!!
댓글 수: 2
답변 (2개)
Stephen23
2018년 9월 11일
편집: Stephen23
2021년 5월 4일
Very similar to the MATLAB documentation shows:
you will want to either use dir or sprint to get the folder names. Something like this should work:
P = 'directory where the 20 subdirectories are';
S = dir(fullfile(P,'*'));
S = S([S.isdir]); % remove files
S = natsortfiles(S); % optional
for k = 1:numel(S)
F = fullfile(P,S(k).name,'filename.txt');
S(k).data = dlmread(F); % or whatever function reads your data.
end
All of your data will be in the structure array S.
댓글 수: 0
Jan
2021년 5월 4일
Folder = 'C:\Base\Folder\';
FileList = dir(fullfile(Folder, '**', 'YourFile.xlsx'));
Data = cell(1, numel(FileList));
for k = 1:numel(FileList)
File = fullfile(FileList(k).folder, FileList(k).name);
Data{k} = readtable(File); % Or however you import the data
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!