Interpolating points in a 3D space with one line
조회 수: 11 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
채택된 답변
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
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)
B = mdl.Coefficients.Estimate
[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')
.
참고 항목
카테고리
Help Center 및 File Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!