sorting

I would like to sort a matrix included of alphabet and values for example a matrix with 10 columns or more the first column is included letter the second is included letter the third is included letter and the rest are values
I would like to know how to sort them based on for example first column then how to sort them based on second column and so on?

댓글 수: 4

Thomas
Thomas 2012년 6월 12일
can you show a small example..
Niki
Niki 2012년 6월 12일
for example
A = {['a' 'b' 'c'] ['d' 'm' 'f'] ['j' 'k' 'l'] [1 2 3] [3 4 7] [1 4 2]}
Thomas
Thomas 2012년 6월 12일
how would you like your sorted output?
Niki
Niki 2012년 6월 12일
for example
based on the first column
but I want to be flexible for example if I want to sort them from the second column, I would like to be able to do that

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

답변 (2개)

Thomas
Thomas 2012년 6월 12일

2 개 추천

A =
'abc' 'dmf' 'jkl' [1x3 double] [1x3 double] [1x3 double]
'pqr' 'abc' 'jkl' [1x3 double] [1x3 double] [1x3 double]
If you want to sort based on first column use
sortrows(A,1) % sort the entire row based on column1
sortrows(A,2) % sort the entire row based on column2 and so on..

댓글 수: 2

Niki
Niki 2012년 6월 12일
is there any other way?
also how can i extract from cell ?
Thomas
Thomas 2012년 6월 12일
A{1,1}
ans =
abc

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

Michael
Michael 2012년 6월 12일

0 개 추천

Check the function called sortrows(matrix, column). It might be helpful for what you want to do.

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

질문:

2012년 6월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by