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

17 次查看(过去 30 天)
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

采纳的回答

Voss
Voss 2022-3-24
编辑:Voss 2022-3-24
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 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by