Replacing a nested for-loop

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 comentarios

Azzi Abdelmalek
Azzi Abdelmalek el 7 de Sept. de 2013
You can not just say replace a double for loop. Give more details about your problem
Ryan
Ryan el 7 de Sept. de 2013
Sorry about that I edited my question. It is more specific now.
Azzi Abdelmalek
Azzi Abdelmalek el 7 de Sept. de 2013
what is myfunction?

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 7 de Sept. de 2013

0 votos

No. arrayfun() uses a for loop internally, so it is no faster.
You should consider vectorizing "myfunction".

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 7 de Sept. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by