Turning iteratively all elements after and above a '1' into '0'-s starting from the left bottom corner
1 回表示 (過去 30 日間)
古いコメントを表示
I have logical square matrices consisting of non-intersecting rectangular patches of '1'-s with no gaps and otherwise '0'-s. 'No gaps' in particular means that two different rectangular patches are not allowed to share horizontal or vertical coordinates. Moreover, the rectangular patches are strictly monotone increasing from the POV of the bottom left corner. For example:
A = [0 0 0 0 1;
0 0 0 0 1;
0 1 1 1 0;
0 1 1 1 0;
1 0 0 0 0]
I would like to perform the following operation on A in a fast way, possibly on GPU. Starting from the left bottom corner, I would like to iteratively turn all elements above and after a '1' into '0'. For example:
B = [0 0 0 0 0;
0 0 0 0 1;
0 0 1 0 0;
0 1 0 0 0;
1 0 0 0 0]
That is, B(3,3) = 1 because after the iteration at A(4,2), A(4,3) turns into a '0'.
My logical matrices are of size at most 15 and I would like to perform this operation on a 3D-array of many such square matrices stacked upon each other in a fast way, hence the request for vectorizability if possible.
7 件のコメント
採用された回答
DGM
2022 年 4 月 13 日
編集済み: DGM
2022 年 4 月 13 日
This might not be particularly efficient, but maybe it's one way (if i'm interpreting it right):
A = [0 0 0 0 0 0 1
0 0 0 0 0 0 1;
0 0 0 0 1 1 0;
0 0 0 0 1 1 0;
0 1 1 1 0 0 0;
0 1 1 1 0 0 0;
1 0 0 0 0 0 0];
D = rot90(hankel(size(A,1):-1:1),2).*A;
D(D==0) = NaN;
Dmin = min(D,[],2);
D = D - (flip(cummax(flip(Dmin)))-1);
output = D==1
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Contour Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!