필터 지우기
필터 지우기

How to sort rows of matrix according ot its amount of Nan?

조회 수: 3 (최근 30일)
Isti
Isti 2012년 4월 24일
The matrix is like this: Data =
1 2 NaN 4 NaN
4 NaN 2 NaN 2
7 1 5 NaN 4
9 4 3 7 NaN
row 1 = 2 NaNs, row 2 = 2 NaNs, row 3 = 1 NaN, row 4 = 1 NaN.
and it can be described like this: [2 2 1 1] what can i do if i want to make it like this:
Data =
7 1 5 NaN 4
9 4 3 7 NaN
1 2 NaN 4 NaN
4 NaN 2 NaN 2
row 1 = 1 NaN, row 2 = 1 NaN, row 3 = 2 NaNs, row 4 = 2 NaNs. and it can be described like this: [1 1 2 2]
what to do? thanks before :)

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 4월 24일
[ii ii] = sort(sum(isnan(Data),2))
out = Data(ii,:)
  댓글 수: 3
Isti
Isti 2012년 5월 7일
what can i do if i want to make a sort in descending way (actually the opponent sort of above)?
thanks before :)
Andrei Bobrov
Andrei Bobrov 2012년 5월 7일
[ii ii] = sort(sum(isnan(Data),2),'descend');
out = Data(ii,:)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by