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 CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by