Borrar filtros
Borrar filtros

Compare two datasets(different sizes) for closest point- code attempted

2 visualizaciones (últimos 30 días)
There have been an number of posts comparing matrices or associating closest points within two matrices. My problem involves two datasets of coordinates x y z. One dataset* A* is about 26300 rows long and dataset B is 26500 rows long. A and B are type double. Some of the coordinates in A are exactly the same as in B. Some of the coordinates in A are within 0.01mm of B. Some of the coordinates in A have the same value of x, y or z meaning that simply comparing one column of the coordinates in A and B is not possible. Some of the coordinates in A are not in B.
My challenge is to identify the coordinates in B that are in A by either finding an exact match in B or by finding points within 0.01mm of coordinates in B. I need to retain a sense of row order- the coordinates are associated to other elements in a larger dataset.
This is my attempt so far. It seems to work but isn't very elegant.
% A is the smaller dataset
% B is the larger dataset
[xi,yi]=size(A);
[xj,yj]=size(B);
C=[];
Out=[];
D=[];
E=[];
false=[];
for i=1:xi;
C=find(A(i,3)==B(:,3));
if length(C)==1;
D=A(i,1)-B(C,1);
E=A(i,2)-B(C,2);
if D>=-0.01 & D<=0.01
Out(i,:)=cat(2,A(i,:),B(C,:),C);
elseif D<-0.01 | D>0.01
Out(i,:)=0;
[x1,y1]=size(false);
false(x1+1,:)=cat(2,i,C);
end
elseif length(C)>1;
[x2,y2]=size(C);
for k=1:x2;
D=A(i,1)-B(C(k),1);
E=A(i,2)-B(C(k),2);
if D>=-0.01 & D<=0.01
T=1
elseif D<0.01 | D>0.01
T=0
end
if T==1
[x5,y5]=size(U)
U(x5+1,:)=C(k);
end
end
if length(U)==1
Out(i,:)=cat(2,A(i,:),B(U,:),U);
elseif length(U)>1
[x3,y3]=size(U);
for l=1:x3
D=A(i,1)-B(U(l),1);
E=A(i,2)-B(U(l),2);
if E>=-0.01 & E<=0.01
S(l)=1
elseif E<0.01 | E>0.01
S(l)=0
end
end
V=find(S==1);
if length(V)==1
Out(i,:)=cat(2,A(i,:),B(U(V),:),U(V));
elseif length(V)>1 | length(V)<1
Out(i,:)=0;
end
end
elseif length(C)<1
Out(i,:)=0;
end
U=[];
V=[];
T=[];
S=[];
end
Advice welcome on how I can improve this code
Mel

Respuestas (0)

Categorías

Más información sobre Cartesian Coordinate System Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by