Quick question about the loop

How do I collect values that were done through the loop?
For example,
M=10:40
for i=0:30;
i=i+1;
A=10+M(i);
end
and the answer just comes out as A=50, instead of A=20:50. What would I do in order to collect the 30 values as matrix?

 Respuesta aceptada

Andrejus
Andrejus el 19 de Oct. de 2014
Editada: Andrejus el 19 de Oct. de 2014

0 votos

try this:
M=10:40
for i=0:30;
i=i+1;
A(i)=10+M(i);
end

1 comentario

Jan
Jan el 19 de Oct. de 2014
Do not increase the value of the loop copunter inside loop.

Iniciar sesión para comentar.

Más respuestas (1)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

JK
el 19 de Oct. de 2014

Respondida:

Jan
el 19 de Oct. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by