Asked by Usman Taya
on 20 Jun 2019 at 3:04

A =

-9 3 -1 9

-4 0 1 -2

-2 5 6 -9

I want to sort it and want to get following result after sort matrix A kindly let me know how i can get following results:

A =

-4 0 1 -2

-2 5 6 -9

-9 3 -1 9

Here matrix A is sort based of sum of each row.

Answer by madhan ravi
on 20 Jun 2019 at 3:33

Edited by madhan ravi
on 20 Jun 2019 at 3:38

Accepted Answer

1) Sum A with respect to rows.

2) Use sort() for sum of rows and collect the second output of it.

3) Use the second output of sort() as the row indices of A.

Usman Taya
on 20 Jun 2019 at 4:11

Hi Madhan Ravi,

Thanks for your answer. Kindly can you explain in matlab codes with about example?

madhan ravi
on 20 Jun 2019 at 4:18

No it’s your homework not mine sorry.

doc sum

doc sort

Usman Taya
on 20 Jun 2019 at 4:38

Thanks.

I have done it

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## madhan ravi (view profile)

Direct link to this comment:https://in.mathworks.com/matlabcentral/answers/467984-matrix-indexing-with-respect-to-sum-of-matrix-raws#comment_716598

## Rena Berman (view profile)

Direct link to this comment:https://in.mathworks.com/matlabcentral/answers/467984-matrix-indexing-with-respect-to-sum-of-matrix-raws#comment_722420

Sign in to comment.