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

조회 수: 5 (최근 30일)
% 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개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by