truncating a long for loop

조회 수: 3 (최근 30일)
Talaria
Talaria 2012년 11월 30일
i wrote a program and it includes a for loop, on running this program matlab says the "for loop is too long, truncating to..."
what does this mean and how does it affect my program?

답변 (1개)

Jos (10584)
Jos (10584) 2012년 11월 30일
편집: Jos (10584) 2012년 11월 30일
Similar to this?
N = Inf ;
for k=1:N,
if k > 10, break ; end
end
which will get you a warning: Warning: FOR loop index is too large. Truncating to 9223372036854775807.
So, check your N!
  댓글 수: 2
Talaria
Talaria 2012년 11월 30일
편집: Talaria 2012년 11월 30일
i know my N is big, actually my N=2^41 my question is whether the loop will complete to N or it will terminate early, is that what truncating means? if not then what does it mean? And does that depend on my computer??
Jan
Jan 2012년 11월 30일
편집: Jan 2012년 11월 30일
Here truncating mean, that the FOR loop cannot "carry" such a large index vector. This is a problem of the internal representation of numbers.
Imagine the processing of a loop iteration takes 1e-3 seconds (a fair assumption). How long will it take to perform 2^41 iterations?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by