frequency of 2D matrix in 3D matrix

조회 수: 1 (최근 30일)
AMRIT JETHI
AMRIT JETHI 2019년 3월 7일
편집: Jos (10584) 2019년 3월 7일
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??

답변 (1개)

Jos (10584)
Jos (10584) 2019년 3월 7일
편집: Jos (10584) 2019년 3월 7일
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, ..)) , ..)), ..)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by