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

2 次查看(过去 30 天)
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 个评论
Adam
Adam 2019-5-3
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 2019-5-3
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)?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by