How to plot all figures in only one plot?

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

 Akzeptierte Antwort

Alan Stevens
Alan Stevens am 24 Aug. 2023
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 Kommentare

GULZAR
GULZAR am 24 Aug. 2023
Thank you so much...
Voss
Voss am 24 Aug. 2023
Bearbeitet: Voss am 24 Aug. 2023
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')

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Version

R2022a

Gefragt:

am 24 Aug. 2023

Bearbeitet:

am 24 Aug. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by