Set of points to Cartesian system

Hello,
what whould be the fastest way to calculate the Cartesian coordinates from a distance matrix? First vertex would be at x=0 y=0 and second vertex at x=0 y=dist(V1V2).
THX

 採用された回答

Matt Tearle
Matt Tearle 2011 年 12 月 8 日

0 投票

You can use cmdscale to reconstruct coordinates from distances. You will need a further restriction to determine the locations uniquely (eg y2 > 0). But here's a way to get what you've specified:
% Make some Euclidean coord data
x = [0 0;0 2*rand - 1;2*rand(5,2) - 1];
% Construct distance matrix
d = squareform(pdist(x))
% Reconstruct Euclidean coords from distances
X = cmdscale(d);
% Shift center to first point
X = bsxfun(@minus,X,X(1,:));
% Rotate so x_2 = 0
alpha = atan2(X(2,1),-X(2,2));
R = [cos(alpha),-sin(alpha);sin(alpha),cos(alpha)];
X = X*R
If you compare X and the original x, you'll see that there can be sign ambiguities. You could nail that down, though, if it matters.

3 件のコメント

Walter Roberson
Walter Roberson 2011 年 12 月 8 日
cmdspace? Interesting; I had never seen that before.
Matt Tearle
Matt Tearle 2011 年 12 月 16 日
Did Walter just say "I had never seen that before"? I think I get some kind of award now...
Walter Roberson
Walter Roberson 2011 年 12 月 16 日
Well, it is part of the Stats toolbox, and I do prefer to use software that works more than 19 times out of 20.

サインインしてコメントする。

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2011 年 12 月 8 日

0 投票

x = zeros(1+length(Dists),1);
y = [0; cumsum(Dists(:))];
Ah, the joys of not providing sufficient examples...
Denny Milakara
Denny Milakara 2011 年 12 月 9 日

0 投票

Thank you guys!
I wasn't aware of 'cmdscale'. Anyways, I need it in 2D so I use from now on mdscale.
I always say that the worst part of Matlab is its help: it prevents people of being aware how powerful Matlab really is.
Cheers

カテゴリ

ヘルプ センター および File ExchangeDimensionality Reduction and Feature Extraction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by