array/cellfun vs. for loop

48 ビュー (過去 30 日間)
David Goldsmith
David Goldsmith 2012 年 6 月 28 日
コメント済み: Rik 2018 年 8 月 20 日
Are arrayfun and cellfun always faster than functionally equivalent for loops? If so, why? (E.g., is it a difference in the library functions they call for implementation?) Finally, is it possible to give a general "order function" by which they're faster (e.g., O(N), O(NlogN), etc.)?

採用された回答

Walter Roberson
Walter Roberson 2012 年 6 月 28 日
For loops are usually faster than arrayfun or cellfun, as the for loop does not need to invoke the function handle each time. The for loop also has opportunities for optimizations between statements that the arrayfun or cellfun would not have.
arrayfun() or cellfun() can be faster to write the code for, as they are a higher level concept. Not always, though: some of the twists one has to go through to create the behaviour as an anonymous function can be messy.
  8 件のコメント
Walter Roberson
Walter Roberson 2018 年 8 月 20 日
I do find the blog article at the link indicated.
Rik
Rik 2018 年 8 月 20 日
Strange. Maybe it was offline temporarily, or my own connection had a hiccup. Anyway, here is a permalink for future reference.

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

その他の回答 (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