Filter löschen
Filter löschen

how to order a matrix?

1 Ansicht (letzte 30 Tage)
Sky Scrapper
Sky Scrapper am 30 Nov. 2018
Kommentiert: Sky Scrapper am 3 Dez. 2018
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?

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 30 Nov. 2018
Bearbeitet: Andrei Bobrov am 1 Dez. 2018
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 Kommentare
Andrei Bobrov
Andrei Bobrov am 3 Dez. 2018
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 am 3 Dez. 2018
it's working properly. Thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by