How to plot data from different folders

13 vues (au cours des 30 derniers jours)
iseng
iseng le 20 Mar 2018
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)

Réponse acceptée

Benjamin Großmann
Benjamin Großmann le 23 Avr 2018
Modifié(e) : Benjamin Großmann le 22 Mai 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

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by