finding distance within a range of distance
이전 댓글 표시
[EDIT: 20110524 01:36 CDT - reformat, clarify - WDR]
Hi I have a matrix as follows.
I =
1 1 5 1 1 1 8
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 5 2 1 1 1
1 1 1 1 1 5 1
1 1 1 1 1 1 1
I need to know whether distances of value 5 with another 5 are in the range 3. Thanks in advance
채택된 답변
추가 답변 (1개)
Wolfgang Schwanghart
2011년 5월 23일
How about
[X,Y] = meshgrid(1:size(I,2),1:size(I,1));
ix = find(I == 5);
d = hypot(bsxfun(@minus,X(ix),X(ix)'),bsxfun(@minus,Y(ix),Y(ix)'));
[ixd,cc] = find(d<=3 & d>0);
II = false(size(I));
II(ix(ixd)) = true;
Cheers, W.
댓글 수: 2
Mohammad Golam Kibria
2011년 5월 24일
Walter Roberson
2011년 5월 24일
Wolfgang's output matrix II has a 1 in each position at which there was originally a 5 that was within a distance of 3 of another 5.
If that output is not what you wanted, then you need to specify the form of the output that you did want.
카테고리
도움말 센터 및 File Exchange에서 Networks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!