Effacer les filtres
Effacer les filtres

How to find unique matrix from given array and corresponding indexes?

1 vue (au cours des 30 derniers jours)
Triveni
Triveni le 28 Août 2021
Commenté : Triveni le 1 Sep 2021
I have
A
A(:,:,1) =
Columns 1 through 2
20 20.05
20.05 20
19.95 20
Column 3
19.95
19.95
20.05
A(:,:,2) =
Columns 1 through 2
20 20.05
20.05 20
19.95 20
Column 3
19.95
19.95
20.05
A(:,:,3) =
Columns 1 through 2
20.05 20
20.05 20
19.95 20
Column 3
19.95
19.95
20.05
>> unique(A)
ans =
19.95
20
20.05
But i need to find out unique matrices and corresponding indexes
B
B(:,:,1) =
Columns 1 through 2
20 20.05
20.05 20
19.95 20
Column 3
19.95
19.95
20.05
B(:,:,2) =
Columns 1 through 2
20.05 20
20.05 20
19.95 20
Column 3
19.95
19.95
20.05
>> index = [1,3]
index =
1 3
In this format B and index.

Réponse acceptée

Chunru
Chunru le 28 Août 2021
A(:,:,1) = [ 20 20.05 19.95
20.05 20 19.95
19.95 20 20.05];
A(:,:,2) = [ 20 20.05 19.95
20.05 20 19.95
19.95 20 20.05];
A(:,:,3) = [ 20.05 20 19.95
20.05 20 19.95
19.95 20 20.05];
% Reshape the matrix and find unique along each row
[uA, iA] = unique(reshape(A, [], size(A,3))', 'rows');
B = reshape(uA', size(A,1), size(A,2), [])
B =
B(:,:,1) = 20.0000 20.0500 19.9500 20.0500 20.0000 19.9500 19.9500 20.0000 20.0500 B(:,:,2) = 20.0500 20.0000 19.9500 20.0500 20.0000 19.9500 19.9500 20.0000 20.0500
iA'
ans = 1×2
1 3
  1 commentaire
Triveni
Triveni le 1 Sep 2021
Thanks for your answer. It is also working for m*n*i size means A(m,n,1:i)) array.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by