MATLAB only plotting most recent graph

3 次查看(过去 30 天)
I don't understand why matlab is only plotting figure 2
t0 = 0; tf = 50; y0 = [-0.5;0.5];
[t,Y] = ode45(@f,[t0,tf],y0,[]);
y=Y(:,1);v=Y(:,2);
[t,Y(:,1),Y(:,2)];
% y in output has 2 columns corresponding to u1 and u2
figure(1);
plot(t, y,'b-', t,v,'r-' )
xlabel('t'); ylabel('y, v = y''');
legend('y(t)','v(t)')
ylim([-2.5,2.5]);xticks(0:10:50);
grid on
figure(2);
plot(y,v); axis square; xlabel('y'); ylabel('v=y''');
ylim([-2.5,2.5])
xlim([-2.5,2.5])
grid on
hold off
% plot the phase plot %----------------------------------------------------------------------
function dydt = f(t,Y)
y = Y(1); v = Y(2);
dydt = [v;-2*sin(t)-v-2*y ];
end
  2 个评论
Torsten
Torsten 2024-7-31
What do you mean ? Both graphs are plotted (see above).
dpb
dpb 2024-7-31
编辑:dpb 2024-7-31
Possibly @Anjana doesn't realize that because the second figure identically overlays the first so only sees the second?
@Anjana - select the second and move it and you'll find the first hidden behind it. (I agree that I find it annoying MATLAB doesn't open them with at least a slight offset so you can select without having to first move.)

请先登录,再进行评论。

回答(1 个)

Jatin
Jatin 2024-8-5
Hi Anjana,
As we can see we are using default figure objects in the code, and all the default figures have same "Position” property. Hence it causes MATLAB to open all default figures at the same location on the screen.
So, you must manually drag the top figure to make the bottom figure visible.
Or you can also set the position of each figure using the “Position” property to manually define the positions of each figure on the screen.
For e.g.,
figure1 = figure('Position', [100, 100, 500, 400]); % [left, bottom, width, height]
figure2 = figure('Position', [650, 100, 500, 400]); % Adjust 'left' to avoid overlap
Kindly refer to the below documentation of “Position” property of figure objects for more details:

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by