MATLAB only plotting most recent graph

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일

0 개 추천

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:

카테고리

도움말 센터File Exchange에서 Labels and Annotations에 대해 자세히 알아보기

제품

태그

질문:

2024년 7월 31일

답변:

2024년 8월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by