Interpolating points in a 3D space with one line
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Annemarie
am 4 Jul. 2022
Bearbeitet: Matt J
am 4 Jul. 2022
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 Kommentare
Akzeptierte Antwort
Star Strider
am 4 Jul. 2022
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')
.
2 Kommentare
Siehe auch
Kategorien
Mehr zu Feature Detection and Extraction finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!