Replacing a nested for-loop

2 vues (au cours des 30 derniers jours)
Ryan
Ryan le 7 Sep 2013
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 commentaires
Ryan
Ryan le 7 Sep 2013
Sorry about that I edited my question. It is more specific now.
Azzi Abdelmalek
Azzi Abdelmalek le 7 Sep 2013
what is myfunction?

Connectez-vous pour commenter.

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by