frequency of 2D matrix in 3D matrix

1 visualización (últimos 30 días)
AMRIT JETHI
AMRIT JETHI el 7 de Mzo. de 2019
Editada: Jos (10584) el 7 de Mzo. de 2019
I have a 3D matrix of size 100X100X40. That means I have 40 100X100 2D matrices. I want to know the number of occurances of each 2D matrix in the 3D matrix.
This is somewhat similar to the unique command we have for elements in 1D array.
How to implement it for 2 D matrices??

Respuestas (1)

Jos (10584)
Jos (10584) el 7 de Mzo. de 2019
Editada: Jos (10584) el 7 de Mzo. de 2019
Convert the 3D N-by-M-by-Z matrix into a 2D Z-by-(N*M) matrix and use unique with the rows option on that. An example:
M3D = cat(3, [1 1 ; 1 1], [1 1; 1 1], [2 2 ; 2 2], [1 1 ; 1 1])
M2D = reshape(M3D, [], size(M3D, 3)).'
[~, i] = unique(M2D, 'rows') ;
Mun3D = M3D(:,:,i)
% which you can also do in an incomprehensible one-liner ;-)
% Mun3D = reshape(transpose(unique(transpose(reshape(M3D, ..)) , ..)), ..)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by