Why is my for loop not working?

Hello, My code is pretty straightforward
for x = 1:3
y = pi/x
end
I want to get the value of y for each x (i.e. x = 1, x = 2, x =3). But when I run this code, I only get the value of y for x = 3 in my workspace.

 Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 6 de Dic. de 2015
Editada: Andrei Bobrov el 6 de Dic. de 2015
y = zeros(3,1);
for x = 1:3
y(x) = pi/x;
end
or without loop
x = 1:3;
y = pi./x;

Más respuestas (0)

Categorías

Más información sobre Statics and Dynamics en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 6 de Dic. de 2015

Editada:

el 6 de Dic. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by