1 | function hboxeq=showeqbox(f,varargin)
|
---|
2 | %SHOWEQBOX Show the equation box of a fit.
|
---|
3 | % H = SHOWEQBOX(F) shows the equation box of the fit F, using the settings
|
---|
4 | % defined in FITPARAM. The fit structure F is obtained from EZFIT. H is a
|
---|
5 | % handle to the equation box.
|
---|
6 | %
|
---|
7 | % Note that SHOWEQBOX interprets the greek symbols in the fitting equation
|
---|
8 | % (latex syntax). The '\' latex symbol must be omitted.
|
---|
9 | %
|
---|
10 | % SHOWEQBOX is automatically called from SHOWFIT or SELECTFIT when the
|
---|
11 | % option 'dispeqboxmode' is set to 'on' in the fitparam.m file.
|
---|
12 | %
|
---|
13 | % Example:
|
---|
14 | % plotsample('power')
|
---|
15 | % f = ezfit('alpha/x^n');
|
---|
16 | % showeqbox(f);
|
---|
17 | %
|
---|
18 | % See also FITPARAM, EZFIT, SHOWFIT, DISPEQFIT.
|
---|
19 |
|
---|
20 | % F. Moisy, moisy_at_fast.u-psud.fr
|
---|
21 | % Revision: 1.14, Date: 2010/07/09
|
---|
22 | % This function is part of the EzyFit Toolbox
|
---|
23 |
|
---|
24 | % History:
|
---|
25 | % 2006/02/08: v1.00, first version.
|
---|
26 | % 2006/02/14: v1.10, compatible with 'y(x)=..' (free function name).
|
---|
27 | % Capital greek letters accepted. Greek letters as
|
---|
28 | % subscript accepted.
|
---|
29 | % 2006/09/06: v1.11, bug fixed when the handle f.hdata is invalid
|
---|
30 | % 2006/10/18: v1.12, bug fixed for fitcolors. accepts the argument fp
|
---|
31 | % 2007/07/24: v1.13, bug fixed when no 2nd parameter given
|
---|
32 | % 2010/07/09: v1.14, now the font size and font name are the same as the
|
---|
33 | % axes of the figure.
|
---|
34 |
|
---|
35 |
|
---|
36 | if nargin>1 % new v1.13
|
---|
37 | if isstruct(varargin{1})
|
---|
38 | fp=varargin{1};
|
---|
39 | end
|
---|
40 | end
|
---|
41 |
|
---|
42 | if ~exist('fp','var')
|
---|
43 | % loads the default fit parameters:
|
---|
44 | try
|
---|
45 | fp=fitparam;
|
---|
46 | catch
|
---|
47 | error('No fitparam file found.');
|
---|
48 | end
|
---|
49 | end
|
---|
50 |
|
---|
51 | if isfield(f,'eq'), % for normal fits (no interpolation):
|
---|
52 | streq = [f.yvar '(' f.xvar ') = ' f.eq];
|
---|
53 |
|
---|
54 | if strcmp(fp.eqreplacemode,'on'),
|
---|
55 | for n=1:length(f.m),
|
---|
56 | streq = strrep(streq, f.param{n}, num2str(f.m(n), fp.numberofdigit));
|
---|
57 | end
|
---|
58 | if length(streq)>fp.maxlengtheq,
|
---|
59 | streq=[streq(1:fp.maxlengtheq) '...'];
|
---|
60 | end
|
---|
61 | streq=greekize(streq);
|
---|
62 | streq={streq};
|
---|
63 | else
|
---|
64 | % truncates the equation string if too long:
|
---|
65 | if length(streq)>fp.maxlengtheq,
|
---|
66 | streq=[streq(1:fp.maxlengtheq) '...'];
|
---|
67 | end
|
---|
68 | streq={greekize(streq)};
|
---|
69 | for n=1:length(f.m),
|
---|
70 | strm = [greekize(f.param{n}) ' = ' num2str(f.m(n), fp.numberofdigit)];
|
---|
71 | streq = {streq{:} strm};
|
---|
72 | end
|
---|
73 | end
|
---|
74 |
|
---|
75 | lastline='';
|
---|
76 | switch lower(fp.corrcoefmode)
|
---|
77 | case 'r', lastline=['R = ' num2str(f.r, fp.numberofdigit) ' '];
|
---|
78 | case 'r2', lastline=['R^2 = ' num2str(f.r^2, fp.numberofdigit) ' '];
|
---|
79 | end
|
---|
80 | if strcmp(fp.linlogdisp,'on')
|
---|
81 | lastline=[lastline '(' f.fitmode ')'];
|
---|
82 | end
|
---|
83 | if ~isempty(lastline)
|
---|
84 | streq = {streq{:} lastline};
|
---|
85 | end
|
---|
86 |
|
---|
87 | else
|
---|
88 | streq=f.name; % for interpolations
|
---|
89 | end
|
---|
90 |
|
---|
91 |
|
---|
92 |
|
---|
93 | % number of fit already present in the figure:
|
---|
94 | numann=length(findall(gcf,'UserData','equationbox'));
|
---|
95 | % position of the new annotation textbox, to avoid overlapping:
|
---|
96 | position = fp.boxlocation+numann*[0.01 -0.01 0 0];
|
---|
97 |
|
---|
98 | % determines the fit color:
|
---|
99 | if ischar(fp.fitcolor) || length(fp.fitcolor)==3
|
---|
100 | fitcolor=fp.fitcolor; % fixed color
|
---|
101 | else
|
---|
102 | fitcolor=[0 0 0]; % default color if no data in the figure
|
---|
103 | if isfield(f,'hdata')
|
---|
104 | if ishandle(f.hdata)
|
---|
105 | co=get(f.hdata); % object properties of the data
|
---|
106 | if isfield(co,'Color'),
|
---|
107 | fitcolor=max(0,min(1,co.Color*fp.fitcolor)); % color indexed from that of the data
|
---|
108 | end
|
---|
109 | end
|
---|
110 | end
|
---|
111 | end
|
---|
112 |
|
---|
113 | if any(strncmpi(varargin,'transparent',5)) % option used with 'selectfit', in order not to hide the data during the selection
|
---|
114 | bgcolor='none';
|
---|
115 | else
|
---|
116 | bgcolor='white';
|
---|
117 | end
|
---|
118 |
|
---|
119 | % changed v1.14
|
---|
120 | hboxeq=annotation(...
|
---|
121 | 'textbox',position,...
|
---|
122 | 'BackgroundColor',bgcolor,...
|
---|
123 | 'Color',fitcolor,...
|
---|
124 | 'EdgeColor',fitcolor,...
|
---|
125 | 'FitBoxToText','on',...
|
---|
126 | 'UserData','equationbox',...
|
---|
127 | 'String',streq,...
|
---|
128 | 'FontSize',get(0,'DefaultAxesFontSize'),...
|
---|
129 | 'FontName',get(0,'DefaultAxesFontName'));
|
---|
130 |
|
---|