Hi, it is a general question, in my matlab code I used a lot of loops, and inner loops as well. The result is it cannot get a solution quickly.
I was told that VC is good at loop, but matlab is not, matlab is good at matrix computation. And if I used a lot of matrix calculation, choose matlab.
Is there some suggestions? Thank you!
No products are associated with this question.
MATLAB is fine with loops. It's been fine with loops for a very long time but yet still carries that mantra that "loops are bad". They're not. There are some steps you can take to ensure that loops are running at their finest such as:
(I'm sure Jan will be able to extend this list 10fold).
Moral of the story is: Don't avoid loops like the plague, avoid the bad things above like the plague.
@Sean: The list includes the most important strategies already. Some further ideas:
X = rand(1e4); tic; Y = sum(sum(X, 2), 1); toc % 0.19 sec, main work along the rows tic; Y = sum(sum(X, 1), 2); toc % 0.17 sec, main work along the columns
0 Comments