Reputation: 350
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?
Upvotes: 0
Views: 13441
Reputation: 5073
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
.
Upvotes: 2