フィルターのクリア

Find unique rows comparing 2 colums?

1 回表示 (過去 30 日間)
Ronan
Ronan 2015 年 9 月 22 日
コメント済み: Ronan 2015 年 9 月 22 日
% code
a = [1,200,400;
2,222,410;
3,300,409;
4, 90, 100;
5, 320, 420;
6, 200, 400;
7, 222, 410;
8, 350, 405;
9, 210, 110;
10, 50, 80;]
if you look at the matrix, the first row at column 2 and 3 has values the same as the 6th row. e.g. a(1,2:3) = a(6,2:3). I m trying to return 'a' where it doesn't include duplicates. so the first, second, sixth and seventh row should only have one instance. Previously I just used a nested for loop to take each row and compare it to all other rows but on a larger scale this is computationally expensive. I was trying out the unique function with rows but it only seems to compare individual row elements to one another rather than compare 2 columns of one row to the other rows.

採用された回答

Thorsten
Thorsten 2015 年 9 月 22 日
unique(a(:, 2:end), 'rows')
  3 件のコメント
Star Strider
Star Strider 2015 年 9 月 22 日
Add the ‘setOrder’ argument 'stable' to keep the original order:
unique(a(:, 2:end), 'rows', 'stable')
Ronan
Ronan 2015 年 9 月 22 日
my version of matlab doesn't support stable but i found a work around for anybody else wanting to know.
% code
a = [1,200,400;
2,222,410;
3,300,409;
4, 90, 100;
5, 320, 420;
6, 200, 400;
7, 222, 410;
8, 350, 405;
9, 210, 110;
10, 50, 80;]
[b,m,n] = unique(a(:, 2:end), 'rows')
values = zeros(length(b),3)
values(:,2:3) = b
values(:,1) = m
Bop = sortrows(values)

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

その他の回答 (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