Find the indices of elements within a submatrix of a larger matrix
5 次查看(过去 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
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?
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!