How to set a polyfit line to zero

24 Ansichten (letzte 30 Tage)
sophp
sophp am 26 Apr. 2020
Beantwortet: Ameer Hamza am 26 Apr. 2020
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')

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 26 Apr. 2020
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')

Weitere Antworten (0)

Kategorien

Mehr zu Biomedical Signal Processing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by