A very odd loop behavior
古いコメントを表示
I encountered a quite odd and unseen behavior in "for" loops. Consider this simple loop:
for i=1:5
Function(rand(1,1))
end
The loop gives the same results, while repeated lines as this:
Function(rand(1,1))
Function(rand(1,1))
Function(rand(1,1))
Function(rand(1,1))
Function(rand(1,1))
Gives 5 different results. What might be the problem? It seems that the "for" loop evaluates the function 5 times with the same argument. This effect is in Wondows, while in Mac system everything goes smoothly and produces different results.
Any advice would be of great value.
採用された回答
その他の回答 (1 件)
Wayne King
2013 年 3 月 14 日
We don't know anything about Function(), but that is certainly not the case in Windows in general
for ii = 1:5
sum([rand(1,1) 0])
end
4 件のコメント
Tomas Iesmantas
2013 年 3 月 14 日
Wayne King
2013 年 3 月 14 日
I would expect so too, but if the function is not too big, you should post it because nobody can help you further without it.
Tomas Iesmantas
2013 年 3 月 14 日
Wayne King
2013 年 3 月 14 日
Understood
カテゴリ
ヘルプ センター および 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!