What is a more efficient way of writing this code?
NumberedOD = [];
for a = 1:(N-1)
for b = (a+1) :N
NumberedOD = [NumberedOD;a, b];
end
end
My aim is to get a list of numbers like this:
1 2
1 3
.
.
1 N
2 3
2 4
.
.

1 件のコメント

Adam
Adam 2017 年 2 月 14 日
編集済み: Adam 2017 年 2 月 14 日
Purely from a pre-allocation perspective you can work out the number of elements there will be in that matrix - it is fixed and calculable so you can preallocated a zeros matrix. I'm sure there is a quicker vectorized way to do it though, I just don't have time to think about it myself right now. I'm sure someone will suggest one though.

サインインしてコメントする。

 採用された回答

Alexandra Harkai
Alexandra Harkai 2017 年 2 月 14 日

3 投票

NumberedOD = nchoosek(1:N, 2);

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

タグ

質問済み:

2017 年 2 月 14 日

回答済み:

2017 年 2 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by