Effacer les filtres
Effacer les filtres

how to order a matrix?

1 vue (au cours des 30 derniers jours)
Sky Scrapper
Sky Scrapper le 30 Nov 2018
Commenté : Sky Scrapper le 3 Déc 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?

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 30 Nov 2018
Modifié(e) : Andrei Bobrov le 1 Déc 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 commentaires
Andrei Bobrov
Andrei Bobrov le 3 Déc 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 le 3 Déc 2018
it's working properly. Thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by