matlab Cartesian,Matlab - Standard Deviation of Cartesian Points

问题

I have an array of cartesian points (column 1 is x values and column 2 is y values) like so:

308 522

307 523

307 523

307 523

307 523

307 523

306 523

How would I go about getting a standard deviation of the points? It would be compared to the mean, which would be a straight line. The points are not that straight line, so then the standard deviation describes how wavy or "off-base" from the straight line the line segment is.

I really appreciate the help.

回答1:

If you are certain the xy data describe a straight line, you'd do the following.

Finding the best fitting straight line equals solving the over-determined linear system Ax = b in a least-squares sense, where

xy = [

308 522

307 523

307 523

307 523

307 523

307 523

306 523];

x_vals = xy(:,1);

y_vals = xy(:,2);

A = [x_vals ones(size(x_vals))];

b = y_vals;

This can be done in Matlab like so:

sol = A\b;

m = sol(1);

c = sol(2);

What we've done now is find the values for m and c so that the line described by the equation y = mx+c best-fits the data you've given. This best-fit line is not perfect, so it has errors w.r.t. the y-data:

errs = (m*x_vals + c) - y_vals;

The standard deviation of these errors can be computed like so:

>> std(errs)

ans =

0.2440

If you want to use the perpendicular distance to the line (Euclidian distance), you'll have to include a geometric factor:

errs = (m*x_vals + c) - y;

errs_perpendicular = errs * cos(atan(m));

Using trig identities this can be reworked to

errs_perpendicular = errs * 1/sqrt(1+m*m);

and of course,

>> std(errs_perpendicular)

ans =

0.2182

If you are not certain that a straight line fits through the data and/or your xy data essentially describe a point cloud around some common centre, you'd do the following.

Find the center of mass (COM):

COM = mean(xy);

the distances of all points to the COM:

dists = sqrt(sum(bsxfun(@minus, COM, xy).^2,2));

and the standard deviation thereof:

>> std(dists)

ans =

0.5059

回答2:

The mean of a set of two-dimensional values is another two-dimensional value, i.e. it's a point, not a line. This point is also known as the centre of mass, I believe.

It's not entirely clear what standard deviation is in this case, but I think it would make sense to define it in terms of distance from the mean.

来源:https://stackoverflow.com/questions/12736336/matlab-standard-deviation-of-cartesian-points

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值