plot plane through set of 3d point

6 ビュー (過去 30 日間)
ha ha
ha ha 2018 年 2 月 28 日
編集済み: ha ha 2018 年 3 月 1 日
Let's say : I have a set of 3d data (x,y,z) from experiment
data=[x1 y1 z1
x2 y2 z2
x3 y3 z3
x4 y4 z4
...........]
I want to plot the plane contain all points by total least square method. The result as follow. How can I plot like sample illustration?

回答 (1 件)

Roger Stafford
Roger Stafford 2018 年 2 月 28 日
編集済み: Roger Stafford 2018 年 2 月 28 日
If X, Y, and Z are vectors of the x,y,z coordinates of your points, do this:
dX = X-mean(X);
dY = Y-mean(Y);
dZ = Z-mean(Z);
XX = sum(dX.^2); YY = sum((dY.^2; ZZ = sum(dZ.^2);
XY = sum(dX.*dY); XZ = sum(dX.*dZ); YZ = sum(dY.*dZ);
A = [XX,XY,XZ;
XY,YY,YZ;
XZ,YZ,ZZ];
[V,D] = eig(A); % <--Corrected
[~,k] = min(diag(D));
Then
V(1,k)*(x-mean(X))+V(2,k)*(y-mean(Y))+V(3,k)*(z-mean(Z)) = 0 % <--Corrected
where V(:,k) is the eigenvector of A with the smallest eigenvalue, and gives the equation for the best fit plane through your points. (Note: The lowercase x, y, and z here refer to coordinates of the equation of the plane.)
You can plot this plane by using an appropriate meshgrid of x,y points along with solving for z in the plane equation making use of the 'surf' command.
  3 件のコメント
Roger Stafford
Roger Stafford 2018 年 2 月 28 日
編集済み: Roger Stafford 2018 年 2 月 28 日
I made a mistake on the 'eig' function which I have corrected above. (Chalk it up to old age.)
ha ha
ha ha 2018 年 2 月 28 日
Can you help me to perform it by using the attached data "ha.txt"

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

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by