Matrix interference infinity loop
古いコメントを表示
When you put a value to the counter, for example more than 15 and at a number of attempts 10000. the matrix interference in Loop indefinitely What is the reason for this and how can I fix the problem
code
m=15;
klp=0;
for i=1:m
klp=klp+1;
lp(klp)=top;
end
lp(klp)=top interference to infinity loop
1 件のコメント
Azzi Abdelmalek
2012 年 12 月 22 日
What are lp and top?
回答 (1 件)
Walter Roberson
2012 年 12 月 22 日
0 投票
Are you sure it is an infinite loop, and not just very slow? You are not preallocating your output array, so every time you add more information to the array, MATLAB has to allocate a new block of memory just slightly larger, and copy the old array, then delete the old array -- for every iteration.
7 件のコメント
mohammed sportman
2012 年 12 月 23 日
mohammed sportman
2012 年 12 月 23 日
Walter Roberson
2012 年 12 月 23 日
You are getting an out of memory error, and then the display starts repeating the same thing over and over again?
You mention something about "number of attempts 10000". I do not see where that is in the code?
mohammed sportman
2012 年 12 月 24 日
Walter Roberson
2012 年 12 月 24 日
Does your code have a try/catch in it? If so then it might be catching the out-of-memory error instead of exiting.
Have you revised your code to pre-allocate the memory yet?
mohammed sportman
2012 年 12 月 24 日
mohammed sportman
2012 年 12 月 24 日
カテゴリ
ヘルプ センター および 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!