# How to generate and save multiple plots?

23 visualizzazioni (ultimi 30 giorni)
Andi il 9 Dic 2021
Commentato: Awais Saeed il 9 Dic 2021
Hi everyone,
MY script generate 185 plots and each plot further consists of 2 subplots. I need to plot both subplots in parallel way, however my cide only show one subplot at a time. May someonbe suuget me how i can modify my script.
clear all
clc
ev_hr=ev_hr';
bbb=ev_bg; % rate calculation
position = 0; % position of plot in subplot
fig_num = 1; % figure() number
for S=1:185
uu=S;
r=bbb(uu); % for first event
data=ev_hr(:,uu);
u=transpose(data);
for n=1:length(u);
dt=n;
for i=1:length(u)-(n-1);
K=u(i:i+n-1);
k=sum(K);
b(i,n)=(k-(r)*(dt))/sqrt(r*dt);
end
end
T=transpose(b);
for ii=1:72
for jj=1:72-(ii-1)
if(ii==1)
b1(ii,jj)=T(ii,jj);
else
b1(ii,jj+(ii-1))=T(ii,jj);
end
end
end
for ii=1:length(b)
for jj=1:72
if(b1(ii,jj)==0)
b1(ii,jj)=nan;
end
end
end
c = NaN(72,24);
c2=[c b1];
x = [-23:72]' ;
y = [1:72]' ;
position = position + 1;
if position > 10; position = 1; fig_num = fig_num + 1,end
figure(fig_num)
subplot(93,2,position); pcolor(x,y,c2);
colorbar
ylabel('Time interval (hours)')
xlabel('Time of the day')
A=A';
uuu=A(:,uu);
ss=sum(uuu);
ss=ss+20
bb=cumsum(uuu);
h=[-23:72];
subplot(93,2,position); plot(h,bb, 'b')
axis([-23 72 0 ss])
end
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Awais Saeed il 9 Dic 2021
Modificato: Awais Saeed il 9 Dic 2021
If you want to plot all of your plots on same plot window then use 'hold on'. If you want to plot each plot individually then you can acheive that as folllowing.
position = 0; % position of plot in subplot
fig_num = 1; % figure() number
for k = 20:30
x = rand(1,1).*linspace(0,2*pi,k);
y = sin(x).*cos(x);
position = position + 1;
% if position >= 5, create a new figure window and reset position value
if position >= 5; position = 1; fig_num = fig_num + 1,end
figure(fig_num)
subplot(2,2,position)
plot(x,y)
% add caption for each plot
caption = sprintf('fig # %d, subplot # %d, k = %d', fig_num,position, k); % Caption for each subplot's position
title(caption, 'FontSize', 10);
xlabel('x')
ylabel('sin(x)')
end
fig_num = 2
fig_num = 3
##### 3 CommentiMostra 1 commento meno recenteNascondi 1 commento meno recente
Andi il 9 Dic 2021
PLease see the main question, still there is a problem.
Awais Saeed il 9 Dic 2021
Are you asking for two plots per subplot? If that's the case than simply update and if condition and subplot() as shown below:
if position >= 3; position = 1; fig_num = fig_num + 1,end
figure(fig_num)
subplot(2,1,position)

Accedi per commentare.

### Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by