How to call multiple subplots in one code?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ana Marie
el 14 de Ag. de 2020
Comentada: Ana Marie
el 16 de Ag. de 2020
I am trying to plot 2-subplots for two scenarios - scenarios 1 and 2, and for two variables - 'temp' and 'weat'. I want results for the 'temp' variable for Scenario 1 and Scenario 2 to appear in one graph. Similarly, I want results of the 'weat' variable to appear in a different sub-plot. Here is my code:
<code lines>
for scenario = 1:2
<code lines that calculate 'temp' and 'weat' variables for both scenarios 1 and 2. In other words, here I've included lines that calculate distinct values for 'temp' and 'weat' for both scenarios>
% Make Figure 1
if scenario == 1
fig1 = subplot(1,2,1);
plot(temp, 'k:');
hold on
elseif scenario == 2
fig1 = subplot(1,2,2);
plot(temp, 'k:');
<save commands for saving Figure 1>
end
% Make Figure 2
if scenario == 1
fig2 = subplot(1,2,1);
plot(weat, 'k:');
hold on
elseif scenario == 2
fig2 = subplot(1,2,2);
plot(weat, 'k:');
<save commands for saving Figure 2>
end
end
The issue is that when Figure 1 is made, the 'temp' and 'weat' variables for scenario 1 appear in Figure 1, and the 'temp' and 'weat variables for scenario 2 appear in Figure 2. What I would want to do is to have Figure 1 with 'temp' results for scenarios 1 and 2; and Figure 2 with 'weat' results for scenarios 1 and 2. I've tried to label the figures as fig1 and fig2, but the issue still persists. I wonder if there is a solution to this issue? I would like to try a solution where I can label the figures distinctly so that the results only appear in the desired figure. Thank you for your help.
0 comentarios
Respuesta aceptada
Sara Boznik
el 14 de Ag. de 2020
Maybe you should try different
if scenario==1
figure(1)
subplot (1,2,1)
plot(temp,'k:')
figure(2)
subplot(1,2,1)
plot(weat,'k:')
elseif scenario==2
figure(1)
subplot (1,2,2)
plot(temp,'k:')
figure(2)
subplot(1,2,2)
plot(weat,'k:')
end
I hope that will help you and good luck.
Más respuestas (0)
Ver también
Categorías
Más información sobre Subplots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!