"symmetrical" rows of matrix

4 ビュー (過去 30 日間)
Michal
Michal 2020 年 2 月 10 日
コメント済み: Michal 2020 年 2 月 11 日
I have integer matrix A (nA x c) with even number of columns (e.g. mod(c,2) = 0) and unique rows.
How to effectivelly (by speed and memory optimized function "symmetricRows") find the "symmetric" rows of matrix A iA1 and iA2, where "symmetric" rows iA1 and iA2 are defined as:
all(A(iA1,1:end/2) == A(iA2,end/2+1:end) & A(iA1,end/2+1:end) == A(iA2,1:end/2),2) = true
Example:
A = [1 1 1 1;
2 2 2 2;
1 2 3 4;
4 3 2 1;
2 2 3 3;
3 4 1 2;
3 3 2 2]
[iA1, iA2] = symmetricRows(A)
iA1 =
1
2
3
5
iA2 =
1
2
6
7
Typical size of matrices A: nA ~ 1e4-1e6, c ~ 60 - 120
The problem is motivated by pre-processing of large dataset, where "symmetrical" rows are irrelevant from the point of user defined distance metric.

採用された回答

Michal
Michal 2020 年 2 月 11 日
編集済み: Michal 2020 年 2 月 11 日
I present the best solution so far:
d = ~pdist2(A(:,1:end/2), A(:,end/2+1:end));
[iA1, iA2] = find(triu(d & d.'));
  4 件のコメント
the cyclist
the cyclist 2020 年 2 月 11 日
Yeah, I should have mentioned that I did my testing on MATLAB Online, so it's probably not the most powerful platform. :-)
Michal
Michal 2020 年 2 月 11 日
Yes, defintely, MATLAB Online is not proper way how to compute any memory or CPU intensive task at all ... :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by