필터 지우기
필터 지우기

Interpolating points in a 3D space with one line

조회 수: 11 (최근 30일)
Annemarie
Annemarie 2022년 7월 4일
편집: Matt J 2022년 7월 4일
Hello,
I have 5 points (black) in a 3D space. I would like to interpolate these points with a linear LINE and get the coefficients of this linear function.
I have just found how to interpolate these points with a surface so far by using the 'linearinterp' command in the curve fitting toolbox (see the attached figure).
Thanks for your help!

채택된 답변

Star Strider
Star Strider 2022년 7월 4일
Try something like this —
rpm = rand(5,1);
dosage = rand(5,1)*0.1;
mass_of_leaves = rand(5,1);
B = [dosage mass_of_leaves ones(size(dosage))] \ rpm
B = 3×1
4.6860 0.3402 -0.0069
x = linspace(min(mass_of_leaves), max(mass_of_leaves), numel(mass_of_leaves));
y = linspace(min(dosage), max(dosage), numel(dosage));
z = [x(:) y(:) ones(size(x(:)))] * B;
figure
plot3(mass_of_leaves, dosage, rpm, 'p')
hold on
plot3(x, y, z, '-k')
hold off
grid on
xlabel('mass of leaves')
ylabel('dosage')
zlabel('rpm')
mdl = fitlm([mass_of_leaves dosage], rpm)
mdl =
Linear regression model: y ~ 1 + x1 + x2 Estimated Coefficients: Estimate SE tStat pValue _________ ________ ________ ________ (Intercept) -0.006867 0.061301 -0.11202 0.92104 x1 0.34018 0.086056 3.953 0.058441 x2 4.686 0.72903 6.4277 0.023359 Number of observations: 5, Error degrees of freedom: 2 Root Mean Squared Error: 0.0479 R-squared: 0.98, Adjusted R-Squared: 0.96 F-statistic vs. constant model: 49.2, p-value = 0.0199
B = mdl.Coefficients.Estimate
B = 3×1
-0.0069 0.3402 4.6860
[ypred,yci] = predict(mdl, [x(:) y(:)]);
figure
plot3(mass_of_leaves, dosage, rpm, 'p')
hold on
plot3(x, y, ypred, '-k')
plot3(x, y, yci, '--k')
hold off
grid on
xlabel('mass of leaves')
ylabel('dosage')
zlabel('rpm')
.
  댓글 수: 2
Annemarie
Annemarie 2022년 7월 4일
Thanks a lot!
Star Strider
Star Strider 2022년 7월 4일
As always, my pleasure!

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

추가 답변 (2개)

Jonas
Jonas 2022년 7월 4일
have a look into the polyfitn() function on FEX

Matt J
Matt J 2022년 7월 4일
편집: Matt J 2022년 7월 4일
You can use linear3dFit() from this FEX submission
Also, a 3D line is not given by a single equation, so it is not clear what you mean by "the coefficients".

카테고리

Help CenterFile Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by