Plots are overriding each other, and I do not know why
Show older comments
I cannot figure out why a new figure is not opening when running the code. If I run each section by themselves, it works but when I put them together it does not work. I use the function figure but it is not working. With the first section if I use figure with it, it works but suddenly stops when working when I add the second section of the code. When the code is run, it only opens the second figure.
clear % clear all variables from Workspace
clc % clear Comand Window
close all% close all figures
h = 10;
A = pi/6;
t = 1:30;
V1 = 100;
[x1, y1, MaxY1, X_at_MaxY1, T_at_MaxY1] = projectile(t, A, V1, h);
V2 = 200;
[x2, y2, MaxY2, X_at_MaxY2, T_at_MaxY2] = projectile(t, A, V2, h);
V3 = 300;
[x3, y3, MaxY3, X_at_MaxY3, T_at_MaxY3] = projectile(t, A, V3, h);
V4 = 400;
[x4, y4, MaxY4, X_at_MaxY4, T_at_MaxY4] = projectile(t, A, V4, h);
V5 = 500;
[x5, y5, MaxY5, X_at_MaxY5, T_at_MaxY5] = projectile(t, A, V5, h);
figure(2)
plot(x1,y1,x2,y2,x3,y3,x4,y4,x5,y5)
title('Vertical Distance vs. Hor') %Give the Graph a title
xlabel('Horizontal Distance (m)') %Lable the X-axis
ylabel('Vertical Distance (m)') %Lable the Y-axis
h = 10;
V = 100;
t = 1:30;
A1 = pi / 6;
[x6, y6, MaxY6, X_at_MaxY6, T_at_MaxY6] = projectile(t, A1, V, h);
A2 = pi / 4;
[x7, y7, MaxY7, X_at_MaxY7, T_at_MaxY7] = projectile(t, A2, V, h);
A3 = pi / 3;
[x8, y8, MaxY8, X_at_MaxY8, T_at_MaxY8] = projectile(t, A3, V, h);
A4 = 7 * pi / 18;
[x9, y9, MaxY9, X_at_MaxY9, T_at_MaxY9] = projectile(t, A4, V, h);
A5 = pi / 2;
[x10, y10, MaxY10, X_at_MaxY10, T_at_MaxY10] = projectile(t, A5, V, h);
figure(2)
plot(x6,y6,x7,y7,x8,y8,x9,y9,x10,y10)
title('Vertical Distance vs. Horizontal nce'); %Give the Graph a title
xlabel('Horizontal Distance (m)'); %Lable the X-axis
ylabel('Vertical Distance (m)'); %Lable the Y-axis
1 Comment
Lukas Hagmeyer
on 12 Nov 2020
This is a very late answer but may helpful for some guys in the future:
I had more or less the same problem with overwritten subplots that I created in a for-loop.
Within the loop, I changed the position of the subplots and this it the problem.
Corrupt the position of the subplot afterwards and they wont disappear.
p = uipanel('Title','Test');
p.Position = [left up width height]; % left up width height
for i = 1 : 10
pax = subplot(10,1,i,'Parent', p); % left up width height
pax.Position(1) = paxLeft;
%pax.Position(2) = height - i * paxHeight; % here the struggle began
pax.Position(3) = paxWidth;
pax.Position(4) = paxHeight;
handles.(['pax' num2str(i)]) = pax;
end
for i = 1: 10
handles.(['pax' num2str(i)]).Position(2) = height - i * paxHeight;
end
Accepted Answer
More Answers (2)
Giovanni Bambini
on 15 Nov 2023
Edited: Giovanni Bambini
on 15 Nov 2023
I have a similar problem.
I'm working on Linux.
The code is too convoluted to share, but, I have several blocks of:
fig1 = figure('Name', 'a name');
movegui(fig, 'northeast');
%plot something
fig2 = ...
%etc.
When I execute the code, figures override each other messing with positions, figure's names, etc.
If I stop the code and move with the F10 key, everything WORKS PERFECTLY. So practically debug is different from execution.
Do you have any idea how to solve it, or if something I'm doing is messing up with the code?
E.
1 Comment
Giovanni Bambini
on 15 Nov 2023
If I add between each block a
pause(0.5);
the code works.
E.
Sven
on 30 Jan 2024
0 votes
I was struggeling with the same issue that consequitive "area" plot commands would overrite the previous "area" plot command.
I found that the setting "NextPlot" of the uiaxes type controls this behaviour.
Solution: Set the property "NextPlot" of an uiaxes handle to "add"
app.handle_to_my_axis.NextPlot = "add";
Available are "add", "replace", "replacechildren", "replaceall"
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
