Removing far points between vectors

조회 수: 3 (최근 30일)
Daniel ziv
Daniel ziv 2017년 5월 15일
편집: KL 2017년 5월 15일
Hello, i have 2 very large vectors which represent points in a 3d image, im interested in removing all points from the first vector that are farther then 'distance' from the second vector. for example: let A=(1 1 1, 10 10 10, 20 20 20) and b be (1 1 1, 2 2 2, 3 3 3), and distance be 5, only point 1 1 1 in a is closer then 5 to a certain point in b therefore the result should be C=(1 1 1)
  댓글 수: 2
Jan
Jan 2017년 5월 15일
편집: Jan 2017년 5월 15일
It is a benefit to use standard Matlab syntax in this forum, although we can guess how the matrix A might look like.
The distance between [1,1,1] and [3,3,3] is less then 5 also. What exactly does "to a certain point" mean here?
Daniel ziv
Daniel ziv 2017년 5월 15일
im sorry about my matlab ileteracy, certain point means any point. like the example if in the example b would also have a point (9,9,9), then the distance would be less then 5 and the point 10 10 10 in A would also be valid and C=[1 1 1; 10 10 10;]

댓글을 달려면 로그인하십시오.

채택된 답변

KL
KL 2017년 5월 15일
편집: KL 2017년 5월 15일
A=[1 1 1; 10 10 10; 20 20 20]
B = [1 1 1; 2 2 2; 3 3 3]
C = A(sqrt(sum((A-B).^2,2))<=5,:) %edited
  댓글 수: 3
Daniel ziv
Daniel ziv 2017년 5월 15일
im sorry A and B do not have the same size
KL
KL 2017년 5월 15일
편집: KL 2017년 5월 15일
As Jan says, the above works only for the matrices of same size. If you want to compare matrices of different sizes and with all the elements in matrix B, then use the following one.
Arep = kron(A,ones(size(B,1),1));
Brep = repmat(B,size(A,1),1);
dAB = sqrt(sum((Arep-Brep).^2,2));
d = mean(reshape(dAB,fliplr(size(A))))
C = A(d<=5,:)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by