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

1 vue (au cours des 30 derniers jours)
Sanzhar Shaimerden
Sanzhar Shaimerden le 12 Sep 2019
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];

Réponse acceptée

Bruno Luong
Bruno Luong le 12 Sep 2019
Modifié(e) : Bruno Luong le 12 Sep 2019
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))

Plus de réponses (0)

Catégories

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

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by