How to plot all figures in only one plot?

2 ビュー (過去 30 日間)
GULZAR
GULZAR 2023 年 8 月 24 日
編集済み: Voss 2023 年 8 月 24 日
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 件のコメント
GULZAR
GULZAR 2023 年 8 月 24 日
Thank you so much...
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 Center および File ExchangeLine Plots についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by