필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Stephanie Diaz
Stephanie Diaz 2019년 5월 3일
댓글: Stephanie Diaz 2019년 5월 3일
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