Opening A directory of folders and accessing data within each folder
Mostra commenti meno recenti
Good Morning
I'm trying to write a batch code which does the following:
Open directory In a loop open each folder in the directory In a loop open each file with a '.res' file type in the folder Perform functions on each file Plot the data from each file Plot the data on top of the file within each folder
Plot the data from the next folder in a different figure
So far I have something like this, although its not really working
mainFolder = dir(foldername);
figNum = 1;
for k = 1:numel (mainFolder.name)
subFolder = dir(mainFolder(k).name,'*.res')
for j = 1:numel (subFolder.name)
rawData = importdata(subFolder(j).name,' ');
timeData = rawData(:,1);
ampData = rawData(:,2);
figure(figNum)
hold on
plot (timeData,ampData)
%other function stuff
end
hold off
figNum = figNum +1;
end
end
Any input would be greatly appreciated!
Risposta accettata
Più risposte (1)
Sean de Wolski
il 17 Gen 2014
Both for-loop signatures look like the following, which is likely invalid.
for k = numel mainFolder.name
What you likely want is
for k = 1:numel(mainFolder)
I.e. the number of folders you wish to loop over (the size of the mainFolder struct).
3 Commenti
Mary
il 17 Gen 2014
Image Analyst
il 17 Gen 2014
Copy and paste is helpful to avoid problems like that.
Mary
il 17 Gen 2014
Categorie
Scopri di più su File Operations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!