How can I force a gradient for a linaar fit
1 次查看(过去 30 天)
显示 更早的评论
Hi, Im am using the following code to perform a fit on my data x,y1.
P = polyfit(x,y1,1)
m=P(1);
c=P(2)
yfit = m*x+c;
hold on;
plot(x,yfit,'b-.');
However, I want to be able to force the gradient to be 0.5.
How can I do this?
0 个评论
采纳的回答
John D'Errico
2016-6-2
编辑:John D'Errico
2016-6-2
You want to force the slope to be 0.5? Then the least squares estimate for the constant term will come most simply from mean.
m = 0.5;
c = mean(y - m*x);
Ok, if you really want to use polyfit, then
c = polyfit(x,y-m*x,0);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!