Turning iteratively all elements after and above a '1' into '0'-s starting from the left bottom corner
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
DGM
le 13 Avr 2022
Modifié(e) : DGM
le 13 Avr 2022
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Contour Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!