Why is my loop not working?

조회 수: 13 (최근 30일)
Firas Guechchati
Firas Guechchati 2022년 9월 12일
편집: Torsten 2022년 9월 12일
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
Ankit
Ankit 2022년 9월 12일
It will only plot the last file. You need to store the thisfile as array.
Firas Guechchati
Firas Guechchati 2022년 9월 12일
@Ankit could you tell me how, i am a newbie :D

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2022년 9월 12일
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
Firas Guechchati
Firas Guechchati 2022년 9월 12일
my goal is to showcase the plot of every file and not in one image
Torsten
Torsten 2022년 9월 12일
편집: Torsten 2022년 9월 12일
Then use
figure(K)
plot (scrList.DDA.amp)
within the loop.
Or read about "subplot":

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by