Replacing a nested for-loop

2 ビュー (過去 30 日間)
Ryan
Ryan 2013 年 9 月 7 日
Hey everyone!
I am doing pairwise comparisons of strings in a cell array using a function that I wrote. Right now I have it in a nested for-loop that looks like this
D = {'string1','string2','stringn'}
for k = 1:numel(D)
for j = k:numel(D)
M(k,j) = myfunction(D{k},D{j});
end
end
This runs fairly slow. My question is there a faster way to do these pairwise comparisons using something like arrayfun?
  3 件のコメント
Ryan
Ryan 2013 年 9 月 7 日
Sorry about that I edited my question. It is more specific now.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 7 日
what is myfunction?

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

採用された回答

Walter Roberson
Walter Roberson 2013 年 9 月 7 日
No. arrayfun() uses a for loop internally, so it is no faster.
You should consider vectorizing "myfunction".
  1 件のコメント
Ryan
Ryan 2013 年 9 月 7 日
Thank you for the comment

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

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