필터 지우기
필터 지우기

Save plots in a for cycle

조회 수: 1 (최근 30일)
Miguel Albuquerque
Miguel Albuquerque 2022년 7월 6일
댓글: Miguel Albuquerque 2022년 7월 7일
Hey guys, I have this code that correlates two signals with a large amount of samples(30 million). I want to see the plot in the code(surf) for all the iterations, maybe, not all, but perhaps skipping one iteration. Meaning I see the plot in one iteration, the next I dont see, the following I see, and so on. How can I make this, so that the plots are saved in PNG perhaps,to a folder in my pc identified with different number so I can see which iteration it was.
I wanted to do this in a good matlab way, since there are a lot of plots.
Thanks in advance
reference_reshaped = reshape(Reference_signal, 1000, 4, []);
surveillance_reshaped = reshape(Surveillance_signal, 1000, 4, []);
counter=1;
sz = size(reference_reshaped);
for i = 1:sz(3)
r = reference_reshaped(:,1,i);
s = surveillance_reshaped(:,1,i);
[afmag3,delay3,doppler3] = ambgfun(r,s,Fs,[250000 250000]);
afmag3(afmag3>1 )= 1;
counter=counter+1
figure;
surf(delay3,doppler3,afmag3,'LineStyle','-.');
shading interp;
axis([-1e-5 1e-5 -2000 2000]);
grid on;
view([140,35]);
colorbar;
ylabel('Doppler (Hz)');
xlabel('Delay(s)');
title('Ambiguity Function Sref');
end
  댓글 수: 2
Abderrahim. B
Abderrahim. B 2022년 7월 6일
Hi!
Some informations are needed to help :
  1. Share reference_signal and Surveillance_signal if possible.
  2. Clarify further your question.
Thanks
Miguel Albuquerque
Miguel Albuquerque 2022년 7월 6일
Thanks in advance,
I cant attach the signals, they are too big, but in format complex double.
I want that the plot on the code is saved to a folder in each iteration. If possible, on first iteration the plot is saved, second iteration the plot is not saved, 3 iteration plot is saved,... So I could reduce the number of plots by half.
If not possible save the plot on each iteration.

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

채택된 답변

Jan
Jan 2022년 7월 6일
편집: Jan 2022년 7월 6일
If you want to create every 2nd image only, simply use:
for i = 1:2:sz(3)
% ^^ then i is [1, 3, 5, ...]
To save the image, simply use exportgraphics and sprintf to create the file name.
Creating a new figure without deleting the old one will let Matlab crash due to exhausted resources. It is much faster to create the figure once only and to modify the graphics object only:
reference_reshaped = reshape(Reference_signal, 1000, 4, []);
surveillance_reshaped = reshape(Surveillance_signal, 1000, 4, []);
counter = 1;
sz = size(reference_reshaped);
FigH = figure;
AxesH = axes(FigH);
SurfH = surf(AxesH, [], [], [],'LineStyle','-.'); % [EDITED]
shading interp;
axis([-1e-5 1e-5 -2000 2000]);
grid on;
view([140,35]);
colorbar;
ylabel('Doppler (Hz)');
xlabel('Delay(s)');
title('Ambiguity Function Sref');
for i = 1:sz(3)
r = reference_reshaped(:,1,i);
s = surveillance_reshaped(:,1,i);
[afmag3,delay3,doppler3] = ambgfun(r,s,Fs,[250000 250000]);
afmag3(afmag3>1 )= 1;
counter=counter+1;
set(SurfH, 'XData',delay3, 'YData', doppler3, 'ZData', afmag3); % [EDITED]
exportgraphics(AxesH, sprintf('Image%07d.png', counter));
end
If you have 15 Million images and the creation and saving takes 0.1 seconds, the code runs for more than 17 days. Checking the images manually will need some years afterwards.
  댓글 수: 3
Jan
Jan 2022년 7월 6일
@Miguel Albuquerque: This was a bug. See [EDITED] in the code.
You can provide test data created by some rand calls. This does not reveal your original data and is compact enough. Most of all the answering persons can test their codes in the forum before posting.
Miguel Albuquerque
Miguel Albuquerque 2022년 7월 7일
Thanks a lot , it works fine

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by