How can I remove redundant rows in matrix with respect two just first three columns?

1 回表示 (過去 30 日間)
Emmanuel
Emmanuel 2016 年 10 月 21 日
回答済み: Walter Roberson 2016 年 10 月 22 日
A= [1,1,4,5,6;
2,7,4,5,7;
1,1,4,2,3;]
I want the matrix to remove redundant elements based on just first three columns, so my result should be
A = [1,1,4,5,6;
2,7,4,5,7]
I tried
unique(A,'rows')
But it works for all the columns. How do I proceed with it?

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 10 月 22 日
[~, ia] = unique(A(:,1:3), 'rows', 'stable');
B = A(ia,:);

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by