How to plot data from different folders

8 次查看(过去 30 天)
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