Convert logical matix 3d to 2d with unknown z

1 vue (au cours des 30 derniers jours)
Odo Luo
Odo Luo le 15 Juil 2022
Commenté : Odo Luo le 15 Juil 2022
Hello,
I have a 3 dimensional logical array . The size of the 3rd dimension changes and I want to convert it to 2dimensional layer.
Currently I do it this way:
% masks is the 3d logical array
[xMask,yMask,zMask]=size(masks);
mask_result= zeros(xMask,yMask);
for m=1: zMask
mask_result = mask_result | masks(:,:,m);
end
Is there a more elegant way to do it ?

Réponse acceptée

Rik
Rik le 15 Juil 2022
The any function can do this for you:
mask_result=any(masks,3)

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by