フィルターのクリア

How to use unique function in 2D matrices?

30 ビュー (過去 30 日間)
Maitham Al Lawati
Maitham Al Lawati 2016 年 10 月 9 日
コメント済み: Maitham Al Lawati 2016 年 10 月 9 日
hello
I would like to know how I can use the unique function in matlab in such a way that i take off similar elements out of the 2D matrix, provided that the unique function does NOT SORT out he matrix and does NOT CHANGE ITS SHAPE
for example, consider x = [1 1 2 2 3 3 4 4; 5 5 6 6 7 7 8 8 ; 9 9 10 10 11 11 12 12]
output x = [1 2 3 4; 5 6 7 8; 9 10 11 12]
when I used unique, I did not find a way that did not play around with the shape of the 2D matrix
  2 件のコメント
Jan
Jan 2016 年 10 月 9 日
Are you sure that all rows contain the same number of unique elements?
Maitham Al Lawati
Maitham Al Lawati 2016 年 10 月 9 日
yes pretty much, I don't really have a problem with the working of the unique function other than the fact that its sorts out everything and changes the 2D matrix to a 1D matrix.

サインインしてコメントする。

採用された回答

Jan
Jan 2016 年 10 月 9 日
x = [1 1 2 2 3 3 4 4; 5 5 6 6 7 7 8 8; 9 9 10 10 11 11 12 12]
nRow = size(x, 1);
c = cell(1, nRow);
for iRow = 1:nRow
c{iRow} = unique(x(iRow, :), 'stable');
end
result = cat(1, c{:}); % Fails if number of unique elements differ
  1 件のコメント
Maitham Al Lawati
Maitham Al Lawati 2016 年 10 月 9 日
thank you

サインインしてコメントする。

その他の回答 (1 件)

Marc Jakobi
Marc Jakobi 2016 年 10 月 9 日
編集済み: Marc Jakobi 2016 年 10 月 9 日
x = [1 1 2 2 3 3 4 4; 5 5 6 6 7 7 8 8 ; 9 9 10 10 11 11 12 12];
y = unique(x','rows')';

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by