About preallocating for speed
Show older comments
Dear Contributers,
There is a " for loop" in my program and Matlab gives me a suggestion to consider "Preallocating" for speed. I want to learn and do that. However, I don't know where to start to learn it. Of course, I looked the documents in mathworks but I found a few documents in there. I can read all of them but I don't want to rush headlong into this topic. Please, I am asking your ideas where I should start from those documents;
By the way, My code is;
for k1 =1: length(X)
for k2 =1: length(X_inv)
DE(k1,k2)= hypot(X(k1)-X_inv(k2), Y(k1)-Y_inv(k2));
end
end
And Matlab suggested me to preallocate the DE
I am not sure whether this question is appropriate for here or not. If it is not okay, accept my apologies.
Accepted Answer
More Answers (1)
Madison Schossow
on 8 Mar 2018
0 votes
try doing length(X):-1:1
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!