How to plot multiple plots repeatedly from a loop?

3 vues (au cours des 30 derniers jours)
Richa
Richa le 14 Avr 2017
Commenté : Richa le 14 Avr 2017
I have a code which has a 'for' loop running three times. For each iteration, the script computes the value of three functions, let F1, F2 and F3. I have:
figure()
for k=1:1:3
some variable computations;
F1(k)=Value1;
F2(k)=Value2;
F3(k)=Value3;
plot(F1,F2);
hold on
end
This script plots F1 against F2 on the same plot for 3 levels of k. Thats what I need. But now I wish to plot F2 with F3 also from the same script. This needs to be a separate plot, but should also consist of all three plots for 3 levels of k. If I add a new 'figure' before writing plot (F2, F3), it will create 3 plots for 3 levels of k, while I need all of them on one plot. Please guide.

Réponse acceptée

Rik
Rik le 14 Avr 2017
There are two options: use a specific figure number for each plot, or use a handle for the two figures. I would advise the first method. Just use figure(1) and figure(2). The second option requires an additional step to create an axis.
f1=figure;
h1=gca;
f2=figure;
h2=gca;
Now you can use the two handles in the plot command. Don't forget that you have to set hold on for each axis separately.
  1 commentaire
Richa
Richa le 14 Avr 2017
Thank you very much for your help Rik.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by