truncating a long for loop
2 次查看(过去 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?
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!