how to sort 2 columns values based on one column

조회 수: 20 (최근 30일)
Zaffar Mughal
Zaffar Mughal 2019년 6월 4일
댓글: Lasse Embøl 2021년 4월 27일
4 9 60 41
5 6 68 34
6 9 61 14
7 8 63 24
1 7 67 26
2 7 66 20
3 8 55 13
4 7 52 28
5 9 62 48
6 8 78 58
7 11 59 44
1 8 77 48
2 8 72 35
3 8 67 23
4 12 61 15
5 8 67 15
6 5 62 24
7 8 67 24
1 7 66 21
2 6 69 25
3 10 65 17
I have 4 column, first one is showing days (where monday=1) and the next ones is showing sleep,Heart Rate and Stress data. I want to sort these columns in another array in the way all the days data turn into descending order,e.g
1 7 67 26
1 8 77 48
1 7 66 21
2 7 66 20
2 8 72 35
2 6 69 25
3...
and so on ... Could someone please help me with this?

채택된 답변

madhan ravi
madhan ravi 2019년 6월 4일
[~,idx]=sort(matrix);
matrix(idx,:) % first column sorted in ascending order if vice versa use 'descend' option
  댓글 수: 3
madhan ravi
madhan ravi 2019년 6월 5일
Not sure what you mean, perhaps it would be better off if you start a new question with all the necessary illustrations.
Lasse Embøl
Lasse Embøl 2021년 4월 27일
What does ~ mean? What does idx mean? What does : mean?
The answers is very convoluted and not generalizable.
How do i, in easy terms, sort A and B column vectors by A column, descending in values?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Rob L
Rob L 2019년 6월 4일
Check help on 'sortrows'.

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by