필터 지우기
필터 지우기

3D line of best fit

조회 수: 9 (최근 30일)
kanai
kanai 2013년 6월 7일
댓글: Matt J 2020년 10월 5일
I have about 50000 points with x,y,z data spread in 3 coloumns in excel. I have managed to create a plane of best fit. (by creating a comma delimited file, importing it, setting each column as a variable, then using the SFTOOL function. This gives me a plane of best fit through the data when I select the plane to be polynomial with degrees x=1 and y=1).
What I cannot seem to do is create a line of best fit through this data. This line must be a straight line and I would like to know the parametric equation of this line.
I would be most grateful if someone could advise me (a complete matlab beginner) how to go about this.
Many thanks
regards
kanai

채택된 답변

Matt J
Matt J 2013년 6월 7일
Suppose the rows of xyz are your data points,
r0=mean(xyz);
xyz=bsxfun(@minus,xyz,r0);
[~,~,V]=svd(xyz,0);
The parametric equation is
r(t) = r0 + t*V(:,1);
  댓글 수: 31
Songqiu
Songqiu 2020년 10월 2일
Hi, Matt,
Thank you very much for your reply.
I have written the following code for calculating the projections of multiple points using a for loop.
Could you please tell me how to avoid using the for loop?
Many thanks.
a = [0, 0, 0];
b = [1, 1, 1];
p = [1, 1, 0];
for i = 2 : 50
p = cat(1, p, [i i 0]);
end
pp = p;
xyz = zeros(size(pp, 1), 3);
for i = 1 : size(pp, 1)
p = pp(i, :);
ap = p-a;
ab = b-a;
xyz(i, :) = a + dot(ap, ab)/dot(ab, ab) * ab;
end
Matt J
Matt J 2020년 10월 5일
ab=(b-a)/norm(b-a);
xyz=(pp-a)*ab(:)*ab + a;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by