How to leave only the elements that appear once per page?

조회 수: 1 (최근 30일)
Sanzhar Shaimerden
Sanzhar Shaimerden 2019년 9월 12일
댓글: Sanzhar Shaimerden 2019년 9월 12일
I have a 3D array. I need to remove any elements that are in the same place but on the next page, and only use the first occurrence at that position a. Eg. so if all pages were to multiply the result would be 0.
I can't assume this 3D array will be the same size in any dimension so I can't hard code solutions such as isMember. I also can't use the unique built-in function because I don't descriminate against all repeating elements but only elements which share a position on pages.
For example, input: A(:,:,1) = [ 1 0 1];
A(:,:,2) = [ 1 1 0];
A(:,:,2) = [ 0 1 1];
the desired output is: A(:,:,1) = [ 1 0 1];
A(:,:,2) = [ 0 1 0];
A(:,:,2) = [ 0 0 0];

채택된 답변

Bruno Luong
Bruno Luong 2019년 9월 12일
편집: Bruno Luong 2019년 9월 12일
If I understand you correctly
% Test data
A=rand(2,2,5)>0.7
B = logical(A.*cumprod(cat(3,ones(size(A(:,:,1))),1-A(:,:,1:end-1)),3))

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by