Is it possible to only plot specific graph in a for loop?

I have a code where i graph a sine wave for every x from 1 to 10, but i only want to graph the sine wave with x=3,7, and 8.
Here's my example code :
---------------------------------------------
t = 0:0.01:2*pi
for x = 1:10
y = sin(x)
plot(t,y)
end
---------------------------------------------
I only want to graph in the same figure when x equals to 3,7,8.
if i use "if", when x is not equal to 3,7,8 , it will erase all the graph recorded.
is it possible?
thankyou

 Respuesta aceptada

VBBV
VBBV el 15 de Dic. de 2022
Editada: VBBV el 15 de Dic. de 2022
t = 0:0.01:2*pi
x = [3 7 8];
for k =1:length( [3 7 8])
y(k,:) = sin(t.*x(k));
end
plot(t,y)
legend('x = 3','x =7','x=8')

Más respuestas (0)

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Productos

Versión

R2022b

Etiquetas

Preguntada:

el 15 de Dic. de 2022

Comentada:

el 21 de Dic. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by