Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
Stephanie Diaz
Stephanie Diaz el 3 de Mayo de 2019
Comentada: Stephanie Diaz el 3 de Mayo de 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 comentarios
Adam
Adam el 3 de Mayo de 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 el 3 de Mayo de 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)?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by