How to plot multiple plots repeatedly from a loop?

5 views (last 30 days)
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.

Accepted Answer

Rik
Rik on 14 Apr 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.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!