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

1 visualizzazione (ultimi 30 giorni)
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];

Risposta accettata

Bruno Luong
Bruno Luong il 12 Set 2019
Modificato: Bruno Luong il 12 Set 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))

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by