Hello,
i have two cell.
Z1={1x3}{1z3} Z2={1x3}{1x3}{1x3}
i need euclidean distance between Z1 a Z2.
can anyone help ?
Thanks.

2 Kommentare

Kevin Claytor
Kevin Claytor am 11 Feb. 2014
Please elaborate?
Euclidean distance is typically between two points eg; (x1,y1) and (x2,y2).
Are the contents of Z1 and Z2 a pair of points? Are the contents of Z1 one half of the pair and the contents of Z2 another half?
Additionally your two cell matrices are of different size, do you want Euclidean distance between the contents of every cell in Z1 to every cell in Z2, or between corresponding cells in Z1 to Z2?
Tomas
Tomas am 11 Feb. 2014
Z1 contais matrix 1x3 ,1x3 - for example Z1{1}=[1x3 double], [1x3 double]
Z2 contains matrix 1x3 1x3 1x3 - for example Z2{1}= [1x3 double], [1x3 double], [1x3 double]
I need euclidean distance between each point between Z{1} and Z{2}. Matrix[1x3] represents in cell Z1 or Z2 one point with 3 coordinates.
Thanks.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Mischa Kim
Mischa Kim am 11 Feb. 2014
Bearbeitet: Mischa Kim am 11 Feb. 2014

0 Stimmen

Thomas, use
pdist([reshape(cell2mat(Z1),2,3); reshape(cell2mat(Z2),3,3)])
assumming that Z1 contains two cells of 1-by-3's, and Z2 contains three cells of 1-by-3's.

5 Kommentare

Tomas
Tomas am 11 Feb. 2014
I can not use pdist, I have to use a own function
How about:
Z = [reshape(cell2mat(Z1),2,3); reshape(cell2mat(Z2),3,3)]';
kk = 1;
for ii = 1:length(Z(1,:))
for jj = (ii+1):length(Z(1,:))
dist(kk) = norm(Z(:,ii) - Z(:,jj));
kk = kk + 1;
end
end
Tomas
Tomas am 11 Feb. 2014
will work for different lengths Z1 or Z2 ?
Mischa Kim
Mischa Kim am 11 Feb. 2014
Bearbeitet: Mischa Kim am 11 Feb. 2014
Well, it works for your specific requirements, but you can easily generalize it. In
cell2mat(Z1),2,3
the 2 denotes the number of vectors, 3 , the length of each vector. Same applies to Z2.
Does that answer your question?
Tomas
Tomas am 11 Feb. 2014
Ok, i understand. Thank you for your help

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Computational Geometry finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 11 Feb. 2014

Kommentiert:

am 11 Feb. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by