can't find line of best fit from simple code
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Em
am 20 Jan. 2022
Kommentiert: Image Analyst
am 28 Jan. 2022
I can't get a line of best fit to my data using the code from the matlab polyfit page. Does anyone know what might be going wrong?
power=[70,56,42,28];
depth90_09 =[2.9000, 3.0000, 4.4000, 1.7000];
Fit = polyfit(power,depth90_09,2);
plot(polyval(Fit,power))
hold on
scatter(power,depth90_09)
Cheers!
0 Kommentare
Akzeptierte Antwort
Star Strider
am 20 Jan. 2022
The first argument to plot must be the independent variable vector. When I added that, it works!
(I broke out the polyval call as a separate assignment, for clarity.)
power=[70,56,42,28];
depth90_09 =[2.9000, 3.0000, 4.4000, 1.7000];
Fit = polyfit(power,depth90_09,2);
Val = polyval(Fit, power);
figure
plot(power, Val)
hold on
scatter(power,depth90_09, 'filled')
.
5 Kommentare
Image Analyst
am 28 Jan. 2022
@Em your code throws an error. What is the value of
depth50mms_09
Are you sure you want a fit and not an interpolation? The quadratic fit looks reasonable to me.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Startup and Shutdown 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!