How to set a polyfit line to zero

25 次查看(过去 30 天)
How do I force this polyfit line through zero? I tried polyfitzero but it returns an error:
x = [0.000484659 0.000927045 0.001328826 0.001670395 0.002119719];
y = [0.00E+0 1.08E+04 2.06E+04 3.21E+04 4.19E+04];
yneg = [0 620.4663 357.383 320.5892 1121.352];
ypos = yneg;
xneg = [0 2.67524E-05 2.17661E-05 3.18628E-05 6.86184E-05];
xpos = xneg;
errorbar(x,y,yneg,ypos,xneg,xpos,'x')
xlabel('[H] (g/g)')
ylabel('1H signal intensity')
p = polyfit(x,y,1)
f = polyval(p,x);
hold on
plot(x,f,'r')

采纳的回答

Ameer Hamza
Ameer Hamza 2020-4-26
Try this. It fits a linear linear curve without the constant term so that the line passes through origin.
x = [0.000484659 0.000927045 0.001328826 0.001670395 0.002119719];
y = [0.00E+0 1.08E+04 2.06E+04 3.21E+04 4.19E+04];
yneg = [0 620.4663 357.383 320.5892 1121.352];
ypos = yneg;
xneg = [0 2.67524E-05 2.17661E-05 3.18628E-05 6.86184E-05];
xpos = xneg;
errorbar(x,y,yneg,ypos,xneg,xpos,'x')
xlabel('[H] (g/g)')
ylabel('1H signal intensity')
p = [x.'\y.' 0];
x_plot = linspace(0, max(x));
f = polyval(p,x_plot);
hold on
plot(x_plot,f,'r')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Biomedical Signal Processing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by