N doesn't increase in 'for loop'

z=1:100; for n=1:100 f(z)=n; end
why f(z) all equals to 101 instead of 1, 2, 3...100 after running.

 Respuesta aceptada

Sean de Wolski
Sean de Wolski el 31 de Ag. de 2016
t = zeros(1,10);
t(1:10) = 3
This is what you're doing. You're setting all of the indices (1:100) equal to n. Thus only the last iteration of the for-loop actually matters.
You probably want something like
for n = 1:100
f(n) = n;
end

Más respuestas (0)

Categorías

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

Etiquetas

Preguntada:

el 31 de Ag. de 2016

Respondida:

el 31 de Ag. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by