Overlapping graphs in figure

4 Ansichten (letzte 30 Tage)
Diego Núñez García
Diego Núñez García am 5 Jul. 2021
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 Kommentar
Image Analyst
Image Analyst am 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');

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 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 Kommentare
Diego Núñez García
Diego Núñez García am 6 Jul. 2021
Thank you, you solved my problem
Sulaymon Eshkabilov
Sulaymon Eshkabilov am 6 Jul. 2021
You are most welcome!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by