フィルターのクリア

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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by