Effacer les filtres
Effacer les filtres

Find the indices of elements within a submatrix of a larger matrix

2 vues (au cours des 30 derniers jours)
Stephanie Diaz
Stephanie Diaz le 3 Mai 2019
Say I have a matrix "B" of ones and zeros and I find a smaller submatrix (with a "range" or radius of 60 cells) within "B" using the following, where "xpos" and "ypos" are x and y coordinates within "B". As an example, if my "xpos" is 1000 and "ypos" is 1000, I form a 60 cell submatrix around this position and call it "B_sub"
subx = max(1,xpos-range):min(n1,xpos+range);
suby = max(1,ypos-range):min(n2,ypos+range);
B_sub = B(subx,suby); %This is the submatrix around matrix B
I would like to find all zeroes in the submatrix, and I do this by the following:
xidx=find(B(subx,suby)==0);
"xidx" gives me the linear indices of zeros within the submatrix "B_sub", but I want to know what the subscript indices of these elements are within the larger matrix "B". I have tried ismember and intersect, but do not get the output I need.
  2 commentaires
Adam
Adam le 3 Mai 2019
Can't you just add max(1,xpos-range) to x and max(1,ypos-range) to y if you use the two output variant of the find function?
Stephanie Diaz
Stephanie Diaz le 3 Mai 2019
I believe the output variant returns only the linear indices of the zero elements. Do I add these indices to max(1,xpos- range) and max(ypos-range)?

Connectez-vous pour commenter.

Réponses (0)

Catégories

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by