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.

 채택된 답변

Sean de Wolski
Sean de Wolski 2016년 8월 31일

0 개 추천

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2016년 8월 31일

답변:

2016년 8월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by