필터 지우기
필터 지우기

how to order a matrix?

조회 수: 1 (최근 30일)
Sky Scrapper
Sky Scrapper 2018년 11월 30일
댓글: Sky Scrapper 2018년 12월 3일
hi,
Say, I have a matrix,
A B C D
-6760,691 0 -1 0
-3380,495 1 -1 1
-6760,691 0 -1 0
-3380,395 -1 0 -1
-3380,395 -1 0 -1
-6760,691 0 -1 0
-3380,495 -1 -1 1
-6760,691 0 -1 0
-3380,395 -1 0 -1
3380,195 1 0 1
And I want to get,
A B C D
-6760,691 0 -1 0
-3380,495 1 -1 1
-1 -1 1
-3380.395 -1 0 -1
3380,195 1 0 1
Here, I need to order the unique values of A which is done on the 1st column. I'll have to write the different patterns of B, C, D on the basis of same value of A. And, if there is any more repeated values of B,C,D for the same value of A, i'll have to keep only 1 pattern (row).
Can anyone please help me?

채택된 답변

Andrei Bobrov
Andrei Bobrov 2018년 11월 30일
편집: Andrei Bobrov 2018년 12월 1일
EDIT
>> B = [-3380.5 1 -1 1
-6760.7 0 -1 0
-3380.4 -1 0 -1
-3380.4 -1 0 -1
-6760.7 0 -1 0
-3380.5 -1 -1 1
-6760.7 0 -1 0
-3380.4 -1 0 -1
3380.2 1 0 1];
>> A = unique(B,'rows')
A =
-6760.7 0 -1 0
-3380.5 -1 -1 1
-3380.5 1 -1 1
-3380.4 -1 0 -1
3380.2 1 0 1
>> A([false;diff(A(:,1)) == 0],1) = nan
A =
-6760.7 0 -1 0
-3380.5 -1 -1 1
NaN 1 -1 1
-3380.4 -1 0 -1
3380.2 1 0 1
>>
  댓글 수: 4
Andrei Bobrov
Andrei Bobrov 2018년 12월 3일
A = [ -3380.5 1 -1 1 0 0 0 0
-6760.7 0 -1 0 0 1 0 0
-3380.4 -1 0 -1 0 1 1 0
-3380.4 -1 0 -1 1 0 0 0
-6760.7 0 -1 0 0 0 1 0
-3380.5 -1 -1 1 1 0 1 0
-6760.7 0 -1 0 1 0 1 1
-3380.4 -1 0 -1 0 0 0 1
3380.2 1 0 1 0 1 0 1];
[~,b] = unique(A(:,1:4),'rows');
B = A(b,:);
B([false;diff(B(:,1))==0],1) = nan;
Sky Scrapper
Sky Scrapper 2018년 12월 3일
it's working properly. Thanks!

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by