MATLAB曲线拟合在图形上显示方程式 [英] MATLAB curve fit display equation on graph
问题描述
有没有一种方法可以在生成的图形上显示curvefit
公式,而不必每次都自己手动写下?通过GUI或命令行,一切正常.有什么办法可以解决吗?
Is there a way to display the curvefit
equation on the graph produced without having to write it down myself manually every time? By GUI or command-line, anything is okay. Any hacks, some way to get around this?
推荐答案
可能最容易使用fit
实用程序,该实用程序与使用curvefit
的非图形等效项:
Probably easiest to use the fit
utility which is the non-graphical equivalent of using curvefit
:
% sample data
x=[1:10]';
y = x+randn(10,1)*0.5;
plot(x,y,'o')
pars=fit(x,y,'poly1');
pars
包含拟合结果,您可以使用
pars
contains the result of the fit, which you can overlay on the plot above with
hold on
plot(pars)
如果要查看各个参数的值,可以键入pars.p1
或pars.p2
(在此示例中,其他型号可能会有其他参数"pn")
If you want to see the values of individual parameters, you can type pars.p1
or pars.p2
(for this example, there may be other parameters "pn" for other models)
要显示在该图上,您可以执行
To display on the figure, you can do something simple like
xpos=3;
ypos=9;
text(xpos,ypos,{num2str([pars.p1;pars.p2])})
有关更多信息,请查阅曲线的文档,或尝试使用help curvefit
或
For more info look into the documentation for curvefit or try help curvefit
or help fit
.
这篇关于MATLAB曲线拟合在图形上显示方程式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!