필터 지우기
필터 지우기

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 CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by