How to set a polyfit line to zero
조회 수: 24 (최근 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')
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Biomedical Signal Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!