フィルターのクリア

Find similar values in a matrix

2 ビュー (過去 30 日間)
lsutiger1
lsutiger1 2016 年 2 月 2 日
編集済み: lsutiger1 2016 年 2 月 2 日
I am currently working with large data sets, on the range of 500k-1m rows of data in any given matrix. (nx3)
I want to know how to sift through the rows of the matrix to see if any of the rows have the same values in them.
ex. [1 2 3; 2 3 4; 3 4 5; 4 5 6; 1 2 3; 5 6 7]
I want to remove the second [1 2 3] row, such that [1 2 3; 2 3 4; 3 4 5; 4 5 6; 5 6 7]
Can anyone help me with this?

採用された回答

Star Strider
Star Strider 2016 年 2 月 2 日
The unique function can help here:
A = [1 2 3; 2 3 4; 3 4 5; 4 5 6; 1 2 3; 5 6 7];
[Au,ia,ic] = unique(A, 'rows', 'stable');
RowIdxFreq = accumarray(ic, 1);
RowIdxFreq =
2
1
1
1
1
The ‘RowIdxFreq’ variable has the frequencies of the occurrences of the rows. Here, row #1 is repeated.
  7 件のコメント
Star Strider
Star Strider 2016 年 2 月 2 日
Without having your matrix to experiment with, I can only guess.
See if adding a cell reference (the ‘{}’ brackets) works:
atomPositions = unique(X{:},'rows','stable');
If you have a relatively ‘uncomplicated’ cell array, that should work. If unique still has problems, you might have to use sprintf to convert the numbers to strings before you do the operations in my code. (I assume ‘atom_names’ are already strings.)
lsutiger1
lsutiger1 2016 年 2 月 2 日
編集済み: lsutiger1 2016 年 2 月 2 日
The matrix is a 2520x3 matrix, and yes, atom_names is a 2520x1 vector of strings. I tried converting it to strings using num2str, which did not work, because then I got a "dimension mismatch" error when num2str converted my matrix into a 2520x33 char. Will try to use sprintf.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by