- loops are efficient,
- the intent is clear,
- debugging is easy,
- your function will get called exactly how many times it needs to be called.
How can I process all the possible pairs of arrays without using 2 nested for loops?
1 回表示 (過去 30 日間)
古いコメントを表示
I have a number of arrays and I want to compute a distance (using a home made function) between all possible pairs.
Right now I have 2 for loops like this
for i=1:(N-1)
for j=(i+1):N
applymyfunction (array(i), array(j))
end
end
I was wondering if there was a way to do this without using nested loops.
Thanks - F.
1 件のコメント
回答 (1 件)
Walter Roberson
2024 年 3 月 17 日
if all(triu(FirstMatrix) == triu(SecondMatrix), 'all')
2 件のコメント
Walter Roberson
2024 年 3 月 18 日
pdist2() or pdist(), specifying a function handle as the distance function.
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!