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 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