Overlapping graphs in figure

2 views (last 30 days)
Here is part of my code. I'm ploting two graphs evaluating several polynomials , I use "delete(gca) and clf " at the begining of the code, but when I run the script with another vaules, I receive in figure(1) the last plot and the actual one.
i=0
figure(1)
hold on
for i=1:length(nodos)-1
plot([nodos(i):0.01:nodos(i+1)],polyval([Mx(:,:,i)],[nodos(i):0.01:nodos(i+1)]),'Color','b','LineWidth',2.5)
hold on
end
xlabel('Longitud de la Viga [m]')
ylabel('Fuerza cortante[N]')
yline(0)
i=0
figure(2)
for i=1:length(nodos)-1
plot([nodos(i):0.01:nodos(i+1)],polyval([Vx(:,:,i)],[nodos(i):0.01:nodos(i+1)]),'Color','b','LineWidth',2.5)
hold on
end
xlabel('Longitud de la Viga [m]')
ylabel('Momento Flector [n*M]')
yline(0)
  1 Comment
Image Analyst
Image Analyst on 5 Jul 2021
Well, we don't have nodos, Vx, and Mx so it's hard for us to reproduce your code or fix it. Please attach your variables in a .mat file with the paperclip icon after you read this:
To save your variables in a .mat file, do this:
save('answers.mat', 'nodos', 'Mx', 'Vx');

Sign in to comment.

Accepted Answer

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 5 Jul 2021
Here is a bit edited and corrected code:
figure()
for i=1:length(nodos)-1
plot([nodos(i):0.01:nodos(i+1)],polyval([Mx(:,:,i)],[nodos(i):0.01:nodos(i+1)]),'-','LineWidth',2.5)
hold on % Different colored lines
end
xlabel('Longitud de la Viga [m]')
ylabel('Fuerza cortante[N]')
yline(0)
figure()
for i=1:length(nodos)-1
plot([nodos(i):0.01:nodos(i+1)],polyval([Vx(:,:,i)],[nodos(i):0.01:nodos(i+1)]),'-','LineWidth',2.5)
hold all % % Different colored lines
end
xlabel('Longitud de la Viga [m]')
ylabel('Momento Flector [n*M]')
yline(0)
  2 Comments
Diego Núñez García
Diego Núñez García on 6 Jul 2021
Thank you, you solved my problem
Sulaymon Eshkabilov
Sulaymon Eshkabilov on 6 Jul 2021
You are most welcome!

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects 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!