Replacing a nested for-loop

2 次查看(过去 30 天)
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.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2013-9-7
No. arrayfun() uses a for loop internally, so it is no faster.
You should consider vectorizing "myfunction".

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by