How to plot and save a figure with consolidated plots as well as splitted plots in loop?

조회 수: 1 (최근 30일)
(For sample) In the below code: The matlab figure contains 3 plots for 5 batches.
In my real code: I have 5 batches with different inputs,
--> i need to plot a figure with consolidated plots ( all 5 batches plots are to be plotted in same figure and to be saved as singles name)
--> i need to plot 5 figures with splitted plots (single batch plots are to be plotted in single figure likewise for 5 cases and to be saved as 5 different names).
I need to include both conditions(above) in single loop. Can someone help me out for this case? Thanks in advance.
  댓글 수: 2
darova
darova 2020년 2월 14일
Why do you use for loop? Why don't you use hold on?
Sindar
Sindar 2020년 2월 14일
in the future, please include code as text in a code block, not as a picture

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

답변 (1개)

Sindar
Sindar 2020년 2월 14일
Presumably you are calculating or loading each batch. To distinguish in this simple example, I add the index to the data
x=[1:5];
y=[10:10:50];
z=sin(x);
a=cos(y);
% prepare figure to separately save each batch
batches_fig = figure;
% prepare figure to compile all batches
total_fig = figure;
hold on
for ind=1:5
% plot and save this batch
figure(batches_fig)
plot(x,y+ind, x,z+ind, x,a+ind)
print(batches_fig,'-djpeg',["batch" + ind + ".jpg"])
% add this batch to the figure compiling all batches
figure(total_fig)
plot(x,y+ind, x,z+ind, x,a+ind)
end
% save the figure compiling all batches
print(total_fig,'-djpeg',["total_fig.jpg"])

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by