How to plot on 2 figures generated inside a for loop without them overlapping ?

% I want the figures to be seperate and not tiled. I'm also trying to avoid creating a 2nd loop for the second figure. The result of the code is that Figure 2 returns empty , while all variables are plotted on figure 3 , with no labels.
I also want to save the figures without displaying them on the command line ? Thanks !
h2 = figure(2);
h3 = figure(3);
for i = 1:length(k)
%%%%%%% Generating first plot
y3 = (1./k(i)).* log(cosh( sqrt(g.*k(i)) .* t) );
displacement2(:,i) = y3;
hold on
h2 = plot(t,displacement2(:,i));
hold off
ax2.Title.String = 'Displacemnt2 vs k';
ax2.XLabel.String = 'time,t [s]';
ax2.YLabel.String = 'Displacement with quadratic friction[m]';
%%%%%%%%%%%%Generating 2nd plot
%Velocity and plot
v3 = sqrt(g./k(i)) * tanh( sqrt(g.*k(i)).* t);
velocity2(:,i) = v3;
hold on
h3 = plot(t,velocity2(:,i));
hold off
ax3 = axes('Parent',h3);
ax3.Title.String = 'velocity2 vs k';
ax3.XLabel.String = 'time,t [s]';
ax3.YLabel.String = 'velocity2 with quadratic friction[m]'
end

 採用された回答

darova
darova 2020 年 5 月 21 日
Here is an example how to switch between figures
figure(1);
plot([0 1],[0 1],'r')
line([0 2],[0 1],'col','b')
figure(2);
plot([1 0],[0 1],'g')

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangePolar Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by