How do you plot multiple functions so they have their own subplot, but all have plots within the same figure window?

15 vues (au cours des 30 derniers jours)
I have 4 equations with a domain of [0,10]. I need to graph the functions so tehy have their own subplot, but also have all teh plots within the same window. I have been trying to use hold on and hold off, but so far that only shows me my last function, not all of them together. Any suggestions or tips?
x=linspace(0,10);
a=x+1;
b=x.^2+x+1;
c=x.^3++x.^2+x+1;
d=x.^4+x.^3++x.^2+x+1;
plot(x,a)
grid
hold on
plot(x,b)
grid
hold on
plot(x,c)
grid
hold on
hold on
figure
plot(x,d)
grid
hold off

Réponse acceptée

Voss
Voss le 24 Mar 2022
Modifié(e) : Voss le 24 Mar 2022
subplots are all in the same figure (a.k.a. window), by definition, so it's not clear exactly what you want to see.
You are seeing the last plot in its own figure (the most recent figure created right after you run the code), but the other plots should still exist, in another figure (perhaps underneath the most recent figure).
x=linspace(0,10);
a=x+1;
b=x.^2+x+1;
c=x.^3++x.^2+x+1;
d=x.^4+x.^3++x.^2+x+1;
plot(x,a)
grid
hold on
plot(x,b)
grid
hold on
plot(x,c)
grid
hold on
hold on
figure
plot(x,d)
grid
hold off
To use subplots instead:
figure()
subplot(2,2,1)
plot(x,a)
grid
hold on
subplot(2,2,2)
plot(x,b)
grid
hold on
subplot(2,2,3)
plot(x,c)
grid
hold on
subplot(2,2,4)
plot(x,d)
grid
hold off

Plus de réponses (0)

Catégories

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

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by