How to plot multiple plots within a for loop using hold on?

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.

Risposte (1)

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 Commenti

Hi Star Strider,
I tried what you said however, it had no effect.
If it helps I have included what the graphs should look like in the ideal situation:
but this is what occurs:
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.

Accedi per commentare.

Categorie

Scopri di più su 2-D and 3-D Plots in Centro assistenza e File Exchange

Richiesto:

il 27 Nov 2016

Commentato:

il 27 Nov 2016

Community Treasure Hunt

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

Start Hunting!

Translated by