How to plot multiple plots within a for loop using hold on?
Afficher commentaires plus anciens
Hello, using the following code, when I plot the graphs matlab gets confused and starts plotting some of the data within other plots.
For i = 1:10
plot(x1, y1)
semilogy(x2,y2)
xlabel('Name')
ylabel('Name')
hold on;
figure
subplot(3,1,1)
plot(x3,y3)
xlabel
ylabel
axis tight;
subplot(3,1,2)
semilogy(x4,y4)
xlabel
ylabel
axis tight;
hold on;
subplot(3,1,3)
semilogy(x5,y5)
xlabel
ylabel
axis tight;
hold on;
end
The result I want to achieve is 2 different plots. One plot using the variables x2 and y2, and a second plot which contains 3 subplots. When I run this code it plots some of the variables x2 and y2 on the subplots. I am unsure as to why this occurs, I believe it is something to do with the hold on part although I'm not sure what part of is wrong.
Réponses (1)
Star Strider
le 27 Nov 2016
0 votes
If I understand your problem correctly, just delete the hold calls in the subplots. It seems to me that you do not need them.
2 commentaires
Tharuka Devendra
le 27 Nov 2016
Modifié(e) : Star Strider
le 27 Nov 2016
Star Strider
le 27 Nov 2016
I have no idea how to interpret those plots, or determine what is ‘wrong’ with them. I suggest you keep experimenting until you get the result you want.
Since I cannot help with this, I will delete my Answer in a few minutes.
Catégories
En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!