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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by