How to sort the matrix according to specific row?

I have a population generated by pop=[pop;x;y;z;cst,fr]; where first 4 rows are x, second 3 rows are y and third 8 rows are z. cst is sum of column 1 and fr is calculated failure rate of column 2.
6 0.876
5 0.99
3 0.939
6 0.876
4 0.837
7 0.959
4 0.953
4 0.873
0 0
5 0.95
3 0.855
4 0.873
4 0.873
5 0.95
6 0.951
66 0.00032352
6 0.876
6 0.876
6 0.965
6 0.965
4 0.953
4 0.837
4 0.953
0 0
3 0.855
6 0.951
5 0.95
0 0
0 0
3 0.855
6 0.951
59 0.00038143
6 0.965
5 0.888
6 0.965
3 0.863
7 0.889
7 0.959
4 0.953
7 0.915
6 0.968
3 0.855
3 0.855
8 0.942
4 0.873
3 0.855
8 0.942
80 0.0002327
How can I sort the specific (16,32,48) rows followed by unchanged (1:15,17:31,33:47)? for example:
6 0.876
6 0.876
6 0.965
6 0.965
4 0.953
4 0.837
4 0.953
0 0
3 0.855
6 0.951
5 0.95
0 0
0 0
3 0.855
6 0.951
59 0.00038143
6 0.876
5 0.99
3 0.939
6 0.876
4 0.837
7 0.959
4 0.953
4 0.873
0 0
5 0.95
3 0.855
4 0.873
4 0.873
5 0.95
6 0.951
66 0.00032352
6 0.965
5 0.888
6 0.965
3 0.863
7 0.889
7 0.959
4 0.953
7 0.915
6 0.968
3 0.855
3 0.855
8 0.942
4 0.873
3 0.855
8 0.942
80 0.0002327
Please help!

 채택된 답변

sixwwwwww
sixwwwwww 2013년 12월 8일
편집: sixwwwwww 2013년 12월 9일

0 개 추천

you can do it as follow:
For example you have your data in variable A then use following line to do it:
A(16:16:end, :) = sortrows(A(16:16:end, :), 1);
I hope it helps. Good luck!

댓글 수: 6

Ash K
Ash K 2013년 12월 9일
It brilliantly worked, Thank you!
you are welcome
sorry, it did sort all the cst (16:16:end) rows but the x,y,z values did not follow it's cst and fr. for example I wanted to sort like this:
from:
a
b
c
2abc
d
e
f
1def
g
h
i
3ghi
to:
d
e
f
1def
a
b
c
2abc
g
h
i
3ghi
I hope I explained correctly. Thank you.
you can do it as follow:
div = numel(A) / 32;
A = (reshape(reshape((sortrows((reshape((reshape(A', 1, []))', [], div))', 31))', 1, []), 2, []))';
Ash K
Ash K 2013년 12월 9일
worked! Thank you sixwwwwwww!
you are welcome

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

추가 답변 (0개)

카테고리

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

태그

질문:

2013년 12월 8일

댓글:

2013년 12월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by