If you are aware of the dimensions of the allocation preallcoate it using:
If you are not aware of dimensions, and you know that it is either a row or a column vector:
x = zeros([],n) ;
x = zeros(m,[]) ;
If you are not sure of dimensions, allocate it as cell:
x = cell([],n) ;
x = cell(m,[]) ;
3 Comments
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/356612-how-to-avoid-this-problem-consider-preallocating-the-memory-for-speed-in-the-below-sample-code#comment_484302
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/356612-how-to-avoid-this-problem-consider-preallocating-the-memory-for-speed-in-the-below-sample-code#comment_484302
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/356612-how-to-avoid-this-problem-consider-preallocating-the-memory-for-speed-in-the-below-sample-code#comment_484306
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/356612-how-to-avoid-this-problem-consider-preallocating-the-memory-for-speed-in-the-below-sample-code#comment_484306
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/356612-how-to-avoid-this-problem-consider-preallocating-the-memory-for-speed-in-the-below-sample-code#comment_484440
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/356612-how-to-avoid-this-problem-consider-preallocating-the-memory-for-speed-in-the-below-sample-code#comment_484440
Sign in to comment.