plot - Write Equation from Fit in Legend, Matlab -


so, i've fitted exponential curve data points using 'fit' , want equation of fitted curve in legend in graph. how can that? want have equation on form y=ce^-xt in legend. can coefficients, c , x fitted curve , put equation inside legend? or can whole equation written out in way? have many plotted graphs grateful if method not time consuming.

edit: perhaps unclear. main problem how should out coefficients fitted line i've plotted. want have equation inside legend in graph. have take out coefficients hand (and how can done?) or can matlab write straight out in, example, excel?

the documentation explains can obtain coefficients derived fit executed c = fit(...),

coef=coeffvalues(c)  c=coef(1) x=coef(2) 

you can create own legend illustrated following example.

defining c , x parameters fits,

% simulate , plot data t= [0:0.1:1]; c = 0.9; x = 1; figure, hold on plot(t,c*exp(-x*t)+ 0.1*randn(1,length(t)),'ok', 'markerfacecolor','k') plot(t,c*exp(-x*t),':k') axis([-.1 1.2 0 1.2])  % here add "legend" line([0.62 0.7],[1 1],'linestyle',':','color','k') text(0.6,1,[ '               ' num2str(c,'%.2f'),' exp(-' num2str(x,'%.2f') ' t)   ' ],'edgecolor','k') set(gca,'box','on') 

example output:

enter image description here

you may have adjust number formatting , size of text box suit needs.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -