sorting specific columns of a matrix

trying not to sort entire matrix just the columns that conforms the rule. the example is a =[8 6 7; 9 6 7; 10 7 8; 9 9 8; 10 9 8; 9 9 10; 10 9 10; 11 9 10]; I want to sort the rows according to 2 and 3 respectively, but if the value on the second row is greater than the value on the third row this columns should also be sorted by the first column descending. The answer should be: b = [8 6 7; 9 6 7; 10 7 8; 10 9 8; 9 9 8; 9 9 10; 10 9 10; 11 9 10]; any advice?

답변 (1개)

Triveni
Triveni 2016년 1월 24일
편집: Triveni 2016년 3월 13일

1 개 추천

out = sort(a, 'descend');
for ascending order
sort(a, 'ascend');

댓글 수: 6

Ozgur Avsar
Ozgur Avsar 2016년 1월 24일
Thanks, but not the correct answer.
Triveni
Triveni 2016년 1월 24일
what's problem??
Ozgur Avsar
Ozgur Avsar 2016년 1월 24일
please look at the 4. and 5. columns.
Triveni
Triveni 2016년 1월 24일
what answer exactly you want???
Ozgur Avsar
Ozgur Avsar 2016년 1월 24일
a = [8 6 7; 9 6 7; 10 7 8; 9 9 8; 10 9 8; 9 9 10; 10 9 10; 11 9 10]; b = [8 6 7; 9 6 7; 10 7 8; 10 9 8; 9 9 8; 9 9 10; 10 9 10; 11 9 10]; b is the answer
Ozgur Avsar
Ozgur Avsar 2016년 1월 24일
b=sortrows(a,[2 3]) but then?

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

카테고리

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

태그

질문:

2016년 1월 24일

편집:

2016년 3월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by