Replacing a nested for-loop

3 views (last 30 days)
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 Comments
Azzi Abdelmalek
Azzi Abdelmalek on 7 Sep 2013
what is myfunction?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 7 Sep 2013
No. arrayfun() uses a for loop internally, so it is no faster.
You should consider vectorizing "myfunction".
  1 Comment
Ryan
Ryan on 7 Sep 2013
Thank you for the comment

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!