How to plot data from different folders

조회 수: 8 (최근 30일)
iseng
iseng 2018년 3월 20일
편집: Benjamin Großmann 2018년 5월 22일
Hi, I want to plot the same named data from different subfolders. The first level of folder is GM and in total 20 of them exists. Then 10 subfolders exist named #pga in each GM folder. I tried to modify and make the following code work but couldnt manage. Can anyone help?
(for g=1:2 for k=1:9
eval(['load num2str(g),gm\',num2str(k/10),'pga\pga',num2str(k/10),'drift.out'])
end
for m=1:9 eval(['maxdrift(m,1)=max(pga0_',num2str(m),'drift(:,2));']); end maxdrift(10,1)=max(pga1_0drift(:,2)); end)

채택된 답변

Benjamin Großmann
Benjamin Großmann 2018년 4월 23일
편집: Benjamin Großmann 2018년 5월 22일
You can get the file information (name, folder, date, ...) of files within subfolders using the dir command and wildcards. e.g. if your are in the folder which contains the #gm folders then the command
files = dir('./*/*/*.out');
will return a struct of all *.out files within all the second level subfolders. You can then easily build a cell arrray of filenames and operate on them using cellfun:
filePaths = fullfile({files(:).folder},{files(:).name});
cellfun(@(x) disp(x),filePaths,'UniformOutput',false); % substitute disp by your function and add a return value to have catch your functions output in a cell

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by