Why is my loop not working?

2 vues (au cours des 30 derniers jours)
Firas Guechchati
Firas Guechchati le 12 Sep 2022
Modifié(e) : Torsten le 12 Sep 2022
dinfo = dir('M:\xxx\IDXX_xxx_xxx_XXXX.XX.XX_XX.XX.XX\**\**\*scrList.mat');
filenames = fullfile({dinfo.folder}, {dinfo.name});
numfiles = length(filenames);
for K = 1:numfiles
thisfile = filenames{K};
load (thisfile)
plot (scrList.DDA.amp)
end
I have a folder with a lot of subfolders. I managed to read them all but when it comes to plotting it didnt really plot every file but only one file instead. Any suggestion how to fix that?
  2 commentaires
Ankit
Ankit le 12 Sep 2022
It will only plot the last file. You need to store the thisfile as array.
Firas Guechchati
Firas Guechchati le 12 Sep 2022
@Ankit could you tell me how, i am a newbie :D

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 12 Sep 2022
You need to use hold on
dinfo = dir('M:\xxx\IDXX_xxx_xxx_XXXX.XX.XX_XX.XX.XX\**\**\*scrList.mat');
filenames = fullfile({dinfo.folder}, {dinfo.name});
numfiles = length(filenames);
for K = 1:numfiles
thisfile = filenames{K};
load (thisfile)
plot (scrList.DDA.amp)
hold on % Prevent subsequent plots from blowing away prior plots.
end
  2 commentaires
Firas Guechchati
Firas Guechchati le 12 Sep 2022
my goal is to showcase the plot of every file and not in one image
Torsten
Torsten le 12 Sep 2022
Modifié(e) : Torsten le 12 Sep 2022
Then use
figure(K)
plot (scrList.DDA.amp)
within the loop.
Or read about "subplot":

Connectez-vous pour commenter.

Catégories

En savoir plus sur Lighting, Transparency, and Shading dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by