How do you plot multiple functions so they have their own subplot, but all have plots within the same figure window?
24 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
Voss
am 24 Mär. 2022
Bearbeitet: Voss
am 24 Mär. 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
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Subplots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!