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))
  1 件のコメント
Sanzhar Shaimerden
Sanzhar Shaimerden 2019 年 9 月 12 日
Thanks! Very smart and elegant.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by