필터 지우기
필터 지우기

Convert logical matix 3d to 2d with unknown z

조회 수: 3 (최근 30일)
Odo Luo
Odo Luo 2022년 7월 15일
댓글: Odo Luo 2022년 7월 15일
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 ?

채택된 답변

Rik
Rik 2022년 7월 15일
The any function can do this for you:
mask_result=any(masks,3)

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by