How to read directory for folders with numbers in Matlab?

9 vues (au cours des 30 derniers jours)
fatemeh Karimi
fatemeh Karimi le 12 Fév 2016
Hi,
I am trying to process data from almost 100 folders containing my data. The name of the folders is like part1, part2,..., part100 and each folder contains 4 .mat files. It is also important to know the order of the folders. How can I read these 100 data folders in a for loop? I tried the following code:
for i=1:100
A(i)= load('part',num2str(i),'\....mat');
end
but it did not work.
Thanks, Fatemeh
  1 commentaire
Jan
Jan le 12 Fév 2016
Whenever you write that something "does not work", post the error message or explain the difference between the result and your expectations.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 12 Fév 2016
Modifié(e) : Jan le 12 Fév 2016
A = cell(4, 100);
BaseFolder = 'C:\YourData';
for iFolder = 1:100
for iFile = 1:4
A(iFile, iFolder) = load(fullfile(BaseFolder, sprintf('part%d', iFolder), ...
sprintf('File%d.mat', iFile));
end
end

Plus de réponses (2)

Image Analyst
Image Analyst le 12 Fév 2016
Use genpath(). See my attached file for a complete demo.

fatemeh Karimi
fatemeh Karimi le 16 Fév 2016
Thank you very much for your response, that worked for me.

Catégories

En savoir plus sur Dynamic System Models dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by