フィルターのクリア

How can I Improve matlab looping

5 ビュー (過去 30 日間)
paulo sigauque
paulo sigauque 2018 年 11 月 28 日
コメント済み: paulo sigauque 2018 年 11 月 29 日
Hi ,
I would like to know if someone can give me the tips to improve my matlab, mainly in "loop" syntax. How to think in the solution of some problems in short time using matlab programming.
I am realy appreciate you help.
Regards

採用された回答

Image Analyst
Image Analyst 2018 年 11 月 28 日
MATLAB looping was dramatically speeded up several years ago. It's no longer that slow, though the belief persists. If you have less than a few million iterations, it will be pretty fast.
One way to speed it up even more, when you have nested loops, is to have the inner-most loop iterate over the left most index, since MATLAB is in column-major mode, meaning it goes down rows in a single column first before moving over to the next column. So, in summary
% Slower:
for row = 1 : rows
for col = 1 : columns
m(row, col) = some formula;
end
end
% Faster:
for col = 1 : columns
for row = 1 : rows
m(row, col) = some formula;
end
end
And that might only hold for very large matrices (millions of elements). For small matrices (a few tens of thousands of elements) you might not notice a difference.
  1 件のコメント
paulo sigauque
paulo sigauque 2018 年 11 月 29 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by