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

5 vues (au cours des 30 derniers jours)
% 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

Réponse acceptée

darova
darova le 21 Mai 2020
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')

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by