MATLAB curve fit display equation on graph

大城市里の小女人 提交于 2019-12-11 19:38:55

问题


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?


回答1:


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 contains the result of the fit, which you can overlay on the plot above with

hold on
plot(pars)

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])})

For more info look into the documentation for curvefit or try help curvefit or help fit.



来源:https://stackoverflow.com/questions/18734071/matlab-curve-fit-display-equation-on-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!