I am getting this preallocation warning
古いコメントを表示

5 件のコメント
Vânia Gonçalves
2022 年 11 月 19 日
Vânia Gonçalves
2022 年 11 月 19 日
Jan
2022 年 11 月 19 日
@Vânia Gonçalves: A general hint is to search in the net at first. Asking an internet search engine for "Matlab preallocate" shows useful explanations already.
Vânia Gonçalves
2022 年 11 月 19 日
回答 (2 件)
Steven Lord
2022 年 11 月 19 日
1 投票
This is a Code Analyzer warning not a run-time warning.
If you're not sure what preallocation is, why it can be important, or how to do it see the first example on this documentation page.
Seriously? If I ask Google, I get e.g.:
- https://www.mathworks.com/help/matlab/matlab_prog/preallocating-arrays.html
- https://www.mathworks.com/matlabcentral/answers/99124-how-do-i-pre-allocate-memory-when-using-matlab
For your code:
...
maxIter = 1000;
x = zeros(maxIter, 1);
y = zeros(maxIter, 1);
while norm(J) > e && i < maxIter
...
end
x = x(1:i); % Crop unused elements
y = y(1:i);
2 件のコメント
Vânia Gonçalves
2022 年 11 月 19 日
Jan
2022 年 11 月 19 日
What does "long" mean? Seconds or hours?
Symbolic calculations need some time. You can use the profiler to find the bottleneck:
doc profile
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!