How to plot all figures in only one plot?

4 次查看(过去 30 天)
How to plot all figures in one plot (like hold on hold off command) using for loop. I don't need 12 subplots. I need 12 figures in one plot.
clc; clearvars; close all;
x=-10:0.1:10;
c=-6:5;
for i=1:length(c)
y=c(i)*x.^(2)+4*x+2;
subplot(3,4,i)
plot(x,y)
xlabel('x')
ylabel('y')
end

采纳的回答

Alan Stevens
Alan Stevens 2023-8-24
Here's one simple way:
x=-pi:0.1:pi;
c=-6:5;
figure
hold on
for i=1:length(c)
y=c(i)*x.^(2)+4*x+2;
plot(x,y)
end
xlabel('x')
ylabel('y')
hold off
  2 个评论
Voss
Voss 2023-8-24
编辑:Voss 2023-8-24
Another option, in case all plotted vectors have the same number of elements, is to make y a matrix:
x=-pi:0.1:pi;
c=-6:5;
figure
y=c.*x(:).^2+4*x(:)+2;
plot(x,y)
xlabel('x')
ylabel('y')

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by