MATLAB Answers

0

how to sort 2 columns values based on one column

Asked by Zaffar Mughal on 4 Jun 2019
Latest activity Commented on by madhan ravi
on 5 Jun 2019
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?

  0 Comments

Sign in to comment.

2 Answers

Answer by madhan ravi
on 4 Jun 2019
 Accepted Answer

[~,idx]=sort(matrix);
matrix(idx,:) % first column sorted in ascending order if vice versa use 'descend' option

  2 Comments

Many thanks! How would I plot this data ? I want to plot all the data on the day's basis, e.g. on day one all the stress level/heart rate/sleep
and then day 2 same
also I want to make comparison of this on week days (1 till 5) and weeekends (6-7)
could you please help? I m totally newbie and have no grip even syntax wise.
Much appreciated for the favor you did already!
Not sure what you mean, perhaps it would be better off if you start a new question with all the necessary illustrations.

Sign in to comment.


Answer by Rob L
on 4 Jun 2019

Check help on 'sortrows'.

  0 Comments

Sign in to comment.