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

1 Ansicht (letzte 30 Tage)
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.

Akzeptierte Antwort

Chunru
Chunru am 28 Aug. 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

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by