Want to change order with sortrows

2 ビュー (過去 30 日間)
Kyoungtak Kim
Kyoungtak Kim 2020 年 3 月 31 日
コメント済み: Kyoungtak Kim 2020 年 3 月 31 日
Hi.
I'm making the matrix with sortrows.
Here is what I want to make it.
20 20 20
20 20 21
20 20 22
20 20 23
20 20 24
20 20 25
20 21 20
20 21 21
20 21 22
20 21 23
20 21 24
20 21 25
20 22 20.....
To do this I tried with this code:
A=[20 21 22 23 24 25];
B=[20 21 22 23 24 25];
C=[20 21 22 23 24 25];
sets = {A, B, C};
[x y z] = ndgrid(sets{:});
cartProd = [x(:) y(:) z(:)];
sorted_cartProd = sortrows(cartProd, 1);
sorted_cartProd
Then I got this.
sorted_cartProd =
20 20 20
20 21 20
20 22 20
20 23 20
20 24 20
20 25 20
20 20 21
20 21 21
20 22 21
20 23 21
20 24 21
20 25 21
20 20 22
20 21 22 ...
What I expect is start from third column but it starts to change from sedone column.
In this case, what should I do?

採用された回答

Walter Roberson
Walter Roberson 2020 年 3 月 31 日
編集済み: Walter Roberson 2020 年 3 月 31 日
sortrows(cartProd,[1 2 3])
or simply
sortrows(cartProd)
  1 件のコメント
Kyoungtak Kim
Kyoungtak Kim 2020 年 3 月 31 日
Thank you.
I might be think too much...
Good night~

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by