How to plot data from different folders

15 views (last 30 days)
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)

Accepted Answer

Benjamin Großmann
Benjamin Großmann on 23 Apr 2018
Edited: Benjamin Großmann on 22 May 2018
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

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!