绘制3D线,Matlab [英] plot 3D line, matlab

查看:114
本文介绍了绘制3D线,Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很标准,但是找不到解决方案.

My question is pretty standard but can't find a solution of that.

我有points = [x,y,z],并想绘制最佳拟合线.

I have points=[x,y,z] and want to plot best fit line.

我正在使用下面给出的功能(和Thanx Smith)

I am using function given below (and Thanx Smith)

% LS3DLINE.M   Least-squares line in 3 dimensions.
%
% Version 1.0    
% Last amended   I M Smith 27 May 2002. 
% Created        I M Smith 08 Mar 2002
% ---------------------------------------------------------------------
% Input    
% X        Array [x y z] where x = vector of x-coordinates, 
%          y = vector of y-coordinates and z = vector of 
%          z-coordinates. 
%          Dimension: m x 3. 
% 
% Output   
% x0       Centroid of the data = point on the best-fit line.
%          Dimension: 3 x 1. 
% 
% a        Direction cosines of the best-fit line. 
%          Dimension: 3 x 1.
% 
% <Optional... 
% d        Residuals. 
%          Dimension: m x 1. 
% 
% normd    Norm of residual errors. 
%          Dimension: 1 x 1. 
% ...>
%
% [x0, a <, d, normd >] = ls3dline(X)

我有一个. 所以等式可能是

I have a. So equation may be

points*a+dist=0

其中dist为最小值.距折纸的距离.

where dist is min. distance from origon.

现在我的问题是如何在3D模式下绘制最佳滤线.

Now my question is how to plot best filt line in 3D.

推荐答案

它有助于实际读取使用奇异值分解的函数的内容.

It helps to actually read the content of the function, which uses Singular Value Decomposition.

% calculate centroid
  x0 = mean(X)';

% form matrix A of translated points
  A = [(X(:, 1) - x0(1)) (X(:, 2) - x0(2)) (X(:, 3) - x0(3))];

% calculate the SVD of A
  [U, S, V] = svd(A, 0);

% find the largest singular value in S and extract from V the
% corresponding right singular vector
  [s, i] = max(diag(S));
  a = V(:, i);

最好的正交拟合线是

P = x0 + a.* t

随着参数t的变化.这是最大变化的方向,这意味着正交方向上的变化最小.点到该线的正交距离的平方和最小.

as the parameter t varies. This is the direction of maximum variation which means that variation in the orthogonal direction is minimum. The sum of the squares of the points' orthogonal distances to this line is minimized.

这与线性回归不同,线性回归使回归线的y变化最小.该回归假定所有误差都在y坐标中,而正交拟合假定x和y坐标中的误差均具有相同的期望量值.

This is distinct from linear regression which minimizes the y variation from the line of regression. That regression assumes that all errors are in the y coordinates, whereas orthogonal fitting assumes the errors in both the x and y coordinates are of equal expected magnitudes.

[信用:Roger Stafford,http://www.mathworks.com/matlabcentral/newsreader/view_thread/294030]

[Credit: Roger Stafford , http://www.mathworks.com/matlabcentral/newsreader/view_thread/294030]

然后,您只需创建一些t并将其绘制:

Then you only need to create some t and plot it:

for t=0:100,
P(t,:) = x0 + a.*t;
end
scatter3(P(:,1),P(:,2),P(:,3));

您可能想改用plot3(),在这种情况下,您只需要一对点即可.由于定义上的一行是无限的,因此由您决定它应该在哪里开始和结束(取决于应用程序).

You may want to use plot3() instead, in which case you need only a pair of points. Since a line is infinite by definition, it is up to you to determine where it should begin and end (depends on application).

这篇关于绘制3D线,Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆