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

2 次查看(过去 30 天)
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