Why is unique() giving me the matrix after eliminating the common rows for these two matrices?

4 ビュー (過去 30 日間)
Devika Waghela
Devika Waghela 2021 年 3 月 8 日
回答済み: Steven Lord 2021 年 3 月 8 日
I have A =
0.0000 0.0000
0.0000 1.0000
0.0000 0.0000
0.0000 1.0000
1.0000 0.0000
1.0000 0.0000
1.0000 1.0000
B =
0.1000 0.1000
0.1000 0.9000
0.1000 0.1000
0.1000 0.9000
0.9000 0.1000
0.9000 0.1000
0.9000 0.9000
After using unique I am still getting the exact same matrix as my output. Can anyone tell me why is that?
  1 件のコメント
Jan
Jan 2021 年 3 月 8 日
編集済み: Jan 2021 年 3 月 8 日
Please post your code and the input data. Currently all we see is A and B and that you mention, that unqiue has been used anywhere.

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

回答 (2 件)

Jan
Jan 2021 年 3 月 8 日
編集済み: Steven Lord 2021 年 3 月 8 日
If you use a matrix as input to unique, a vector is replied. So if you matrix is not changed, it cannot be an output of unique(). Because you did not post your code, I guess something like this happens:
B = [0.1000 0.1000
0.1000 0.9000
0.1000 0.1000
0.1000 0.9000
0.9000 0.1000
0.9000 0.1000
0.9000 0.9000];
unique(B); % This is no effect!
% You need:
uB = unique(B)
% Or maybe:
uB = unique(B, 'rows')
[SL: fixed typo]

Steven Lord
Steven Lord 2021 年 3 月 8 日
If you're trying to find unique rows, two rows that display the same may not contain the same stored values.
A = [1 2; 1+eps 2] % First and second rows are NOT the same
A = 2×2
1.0000 2.0000 1.0000 2.0000
unique(A, 'rows')
ans = 2×2
1.0000 2.0000 1.0000 2.0000
To allow "close enough" to count you'd want to use uniquetol.
uniquetol(A, eps, 'ByRows', true)
ans = 1×2
1 2

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by