I am getting this preallocation warning

조회 수: 1 (최근 30일)
Vânia Gonçalves
Vânia Gonçalves 2022년 11월 19일
댓글: Jan 2022년 11월 19일
  댓글 수: 5
Jan
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
Vânia Gonçalves 2022년 11월 19일
hi
i already searched in the internet, but i didn´t find any usefull explanation, so i hoped find help here.
but thanks anyawy

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

답변 (2개)

Steven Lord
Steven Lord 2022년 11월 19일
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.

Jan
Jan 2022년 11월 19일
이동: Jan 2022년 11월 19일
Seriously? If I ask Google, I get e.g.:
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
Vânia Gonçalves 2022년 11월 19일
Thanks for your help
i tried you advice
is it normal to take a long time to run?
Jan
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

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

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by