MATLAB only plotting most recent graph
3 views (last 30 days)
Show older comments
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 Comments
dpb
on 31 Jul 2024
Edited: dpb
on 31 Jul 2024
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.)
Answers (1)
Jatin
on 5 Aug 2024
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:
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!