1 | function efmenu(opt)
|
---|
2 | %EFMENU Ezyfit menu
|
---|
3 | % EFMENU adds or refreshes the Ezyfit menu for the current figure and
|
---|
4 | % for all new figures.
|
---|
5 | % EFMENU OFF removes the menu from all the figures and for all new
|
---|
6 | % figures.
|
---|
7 | %
|
---|
8 | % Careful: when the Ezyfit menu is active, all saved figure files (.FIG)
|
---|
9 | % include the Ezyfit menu. This generates a problem when those figure
|
---|
10 | % files are opened in a Matlab system which does not have the Ezyfit
|
---|
11 | % toolbox installed. In order to remove the Ezyfit menu from the figure
|
---|
12 | % file, use the function REMOVE_EFMENU_FIG.
|
---|
13 | %
|
---|
14 | % If you want to always have the EzyFit menu in your figures, type
|
---|
15 | % EFMENU INSTALL. This will create or update the 'startup.m' file in the
|
---|
16 | % user directory of your Matlab installation. In addition, at
|
---|
17 | % each Matlab restart, this will check the last version of the EzyFit
|
---|
18 | % toolbox on the web (see CHECKUPDATE_EF).
|
---|
19 | %
|
---|
20 | % In order to cancel the effect of EFMENU INSTALL, you need to edit the
|
---|
21 | % 'startup.m' file and to remove manually the 2 lines of code related to
|
---|
22 | % the Ezyfit toolbox.
|
---|
23 | %
|
---|
24 | % See also PLOTSAMPLE, SHOWFIT, EZFIT, UNDOFIT, RMFIT, EDITFIT,
|
---|
25 | % LOADFIT, CHECKUPDATE_EF, REMOVE_EFMENU_FIG.
|
---|
26 |
|
---|
27 | % F. Moisy, moisy_at_fast.u-psud.fr
|
---|
28 | % Revision: 1.80, Date: 2012/07/02
|
---|
29 | % This function is part of the EzyFit Toolbox
|
---|
30 |
|
---|
31 | % History:
|
---|
32 | % 2005/12/06: v1.00, first version.
|
---|
33 | % 2005/12/16: v1.01, works with all new figures.
|
---|
34 | % 2006/01/12: v1.10, User defined fits improved.
|
---|
35 | % 2006/01/19: v1.20, User defined fits improved again.
|
---|
36 | % 2006/01/30: v1.21, bug fixed with selectfit. New fit fgauss.
|
---|
37 | % 2006/02/08: v1.30, use a new mat-file for user defined fits.
|
---|
38 | % polynomial orders as a submenu. New 'Edit Fit Coeff'.
|
---|
39 | % Check for update when launched from startup.m
|
---|
40 | % 2006/02/16: v1.31, item 'Show Fit Residual' added
|
---|
41 | % 2006/02/27: v1.40, option 'install' added.
|
---|
42 | % 2006/03/07: v1.41, option 'install' improved (append to startup.m), and
|
---|
43 | % bug fixed for check of the ml version
|
---|
44 | % 2006/04/10: v1.42, toobox renamed 'EzyFit'
|
---|
45 | % 2006/04/24: v1.43, bugs in option 'install' fixed (did not correctly
|
---|
46 | % recognize if the toolbox was already installed)
|
---|
47 | % 2006/09/06: v1.44, submenu for 'PlotSample'
|
---|
48 | % 2007/09/12: v1.45, new menu 'Refresh EzyFit menu'
|
---|
49 | % 2007/09/14: v1.46, bug fixed with 'install off' (case sensitive); options
|
---|
50 | % modified for getslope and showslope
|
---|
51 | % 2007/09/18: v1.50, new submenus for Gaussian fits
|
---|
52 | % 2008/03/06: v1.51, Ctrl-Z removed (conflicts)
|
---|
53 | % 2008/03/14: v1.60, selectfit removed for Ezyfit >= 2.30 (replaced by
|
---|
54 | % showfit in "Brushed" mode)
|
---|
55 | % 2009/02/04: v1.61, help text 'uninstall' added
|
---|
56 | % 2010/07/07: v1.70, help text 'remove_efmenu_fig' added
|
---|
57 | % 2012/06/28: v1.71, check update removed
|
---|
58 | % 2012/07/02: v1.80, change working directory, for Windows 7 compatibility
|
---|
59 | % 2012/08/01: v1.81, change for under MacOS X, Matlab 2012 (thanks J. Bagrow)
|
---|
60 |
|
---|
61 |
|
---|
62 |
|
---|
63 | % check the matlab version:
|
---|
64 | % if str2double(version('-release'))<14,
|
---|
65 | % error('EzyFit requires Matlab 7 (R14) or higher.');
|
---|
66 | % end
|
---|
67 |
|
---|
68 | % if efmenu is called from the file startup.m, then calls
|
---|
69 | % the Check Update for the Ezyfit Toolbox:
|
---|
70 | st=dbstack;
|
---|
71 | if length(st)>=2
|
---|
72 | if strcmp(st(2).name,'startup'),
|
---|
73 | checkupdate_ef;
|
---|
74 | end
|
---|
75 | end
|
---|
76 |
|
---|
77 |
|
---|
78 | if nargin==0
|
---|
79 | opt='on';
|
---|
80 | end
|
---|
81 |
|
---|
82 | % new v1.30:
|
---|
83 | userfit=loadfit('user');
|
---|
84 |
|
---|
85 | switch lower(opt)
|
---|
86 | case 'off'
|
---|
87 | set(0,'DefaultFigureCreateFcn','');
|
---|
88 | delete(findobj('Label','EzyFit')); % delete the menu from all the figures.
|
---|
89 | case 'install'
|
---|
90 | install_ef;
|
---|
91 | case 'on'
|
---|
92 | set(0,'DefaultFigureCreateFcn','efmenu');
|
---|
93 | if get(0,'CurrentFigure')
|
---|
94 | delete(findobj(gcf,'Label','EzyFit')); % delete the menu only from the current figure
|
---|
95 | h=uimenu('Label','EzyFit');
|
---|
96 | uimenu(h,'Label','Undo fit','Callback','undofit'); % Ctrl-Z removed march 7, 2008
|
---|
97 | uimenu(h,'Label','Remove all fits','Callback','rmfit');
|
---|
98 |
|
---|
99 | %submenu showfit and selectfit:
|
---|
100 | hm(1)=uimenu(h,'Separator','on','Label','Show Fit');
|
---|
101 | menuname{1}='showfit';
|
---|
102 | %hm(2)=uimenu(h,'Label','Select Fit');
|
---|
103 | %menuname{2}='selectfit';
|
---|
104 | for i=1:1, % only "showfit" is visible for EzyFit >=2.30
|
---|
105 | uimenu(hm(i),'Label','Constant','Callback',['lastfit=' menuname{i} '(''cste'');']);
|
---|
106 | hlin=uimenu(hm(i),'Label','Linear');
|
---|
107 | uimenu(hlin,'Label','a*x','Callback',['lastfit=' menuname{i} '(''linear'');']);
|
---|
108 | uimenu(hlin,'Label','a*x+b','Callback',['lastfit=' menuname{i} '(''affine'');']);
|
---|
109 | uimenu(hlin,'Label','a*(x-b)','Callback',['lastfit=' menuname{i} '(''affineshift'');']);
|
---|
110 | hpol=uimenu(hm(i),'Label','Polynomial');
|
---|
111 | for or=1:6,
|
---|
112 | uimenu(hpol,'Label',['Order ' num2str(or)],...
|
---|
113 | 'Callback',['lastfit=' menuname{i} '(''poly' num2str(or) ''');']);
|
---|
114 | end
|
---|
115 | uimenu(hpol,'Label','Other...','Separator','on','Callback',['lastfit=' menuname{i} '(''poly'');']);
|
---|
116 | hexp=uimenu(hm(i),'Label','Exponential');
|
---|
117 | uimenu(hexp,'Label','a*exp(b*x)','Callback',['lastfit=' menuname{i} '(''exp'');']);
|
---|
118 | uimenu(hexp,'Label','a*exp(b*x)+c','Callback',['lastfit=' menuname{i} '(''expc'');']);
|
---|
119 | uimenu(hexp,'Label','a*exp(x/b)','Callback',['lastfit=' menuname{i} '(''expdiv'');']);
|
---|
120 | uimenu(hexp,'Label','a*(1-exp(-x/b))','Callback',['lastfit=' menuname{i} '(''explim'');']);
|
---|
121 | hlog=uimenu(hm(i),'Label','Logarithmic');
|
---|
122 | uimenu(hlog,'Label','a*log(b*x)','Callback',['lastfit=' menuname{i} '(''log'');']);
|
---|
123 | uimenu(hlog,'Label','a*log(x)+b','Callback',['lastfit=' menuname{i} '(''logc'');']);
|
---|
124 | hpow=uimenu(hm(i),'Label','Power');
|
---|
125 | uimenu(hpow,'Label','a*x^n','Callback',['lastfit=' menuname{i} '(''power'');']);
|
---|
126 | uimenu(hpow,'Label','a*x^n+c','Callback',['lastfit=' menuname{i} '(''powerc'');']);
|
---|
127 | uimenu(hpow,'Label','a*(x+b)^n','Callback',['lastfit=' menuname{i} '(''powershift'');']);
|
---|
128 | hgauss=uimenu(hm(i),'Label','Gaussian');
|
---|
129 | uimenu(hgauss,'Label','Centered Normalized Gaussian','Callback',['lastfit=' menuname{i} '(''cngauss'');']);
|
---|
130 | uimenu(hgauss,'Label','Centered Non-normalized Gaussian','Callback',['lastfit=' menuname{i} '(''cfgauss'');']);
|
---|
131 | uimenu(hgauss,'Label','Non-centered Normalized Gaussian','Callback',['lastfit=' menuname{i} '(''ngauss'');']);
|
---|
132 | uimenu(hgauss,'Label','Non-centered Non-normalized Gaussian','Callback',['lastfit=' menuname{i} '(''fgauss'');']);
|
---|
133 | hosc=uimenu(hm(i),'Label','Oscillations');
|
---|
134 | uimenu(hosc,'Label','a*sin(b*x)','Callback',['lastfit=' menuname{i} '(''sin'');']);
|
---|
135 | uimenu(hosc,'Label','a*cos(b*x)','Callback',['lastfit=' menuname{i} '(''cos'');']);
|
---|
136 | uimenu(hosc,'Label','a*sin(b*x)+c','Callback',['lastfit=' menuname{i} '(''sinc'');']);
|
---|
137 | uimenu(hosc,'Label','a*cos(b*x)+c','Callback',['lastfit=' menuname{i} '(''cosc'');']);
|
---|
138 | uimenu(hosc,'Label','a*sin(b*x+phi)','Callback',['lastfit=' menuname{i} '(''sinphi'');']);
|
---|
139 | uimenu(hosc,'Label','a*sin(b*x+phi)+c','Callback',['lastfit=' menuname{i} '(''sinphic'');']);
|
---|
140 | uimenu(hm(i),'Label','Nearest','Separator','on','Callback',[menuname{i} '(''nearest'');']);
|
---|
141 | uimenu(hm(i),'Label','Spline','Callback',[menuname{i} '(''spline'');']);
|
---|
142 | uimenu(hm(i),'Label','Cubic','Callback',[menuname{i} '(''cubic'');']);
|
---|
143 |
|
---|
144 | for j=1:length(userfit)
|
---|
145 | if j==1,
|
---|
146 | uimenu(hm(i),'Label',['#' num2str(j) ': ' userfit(j).name],...
|
---|
147 | 'Separator','on','Callback',['lastfit=' menuname{i} '(''' userfit(j).eq ''');']);
|
---|
148 | else
|
---|
149 | uimenu(hm(i),'Label',['#' num2str(j) ': ' userfit(j).name],...
|
---|
150 | 'Callback',['lastfit=' menuname{i} '(''' userfit(j).eq ''');']);
|
---|
151 | end
|
---|
152 | end
|
---|
153 | uimenu(hm(i),'Label','Other...','Separator','on','Callback',[menuname{i} ';']);
|
---|
154 | end
|
---|
155 |
|
---|
156 | %submenu edit fit:
|
---|
157 | hef=uimenu(h,'Label','Edit User Fit');
|
---|
158 | for j=1:length(userfit)
|
---|
159 | uimenu(hef,'Label',['#' num2str(j) ': ' userfit(j).name],'Callback',['editfit(' num2str(j) ')']);
|
---|
160 | end
|
---|
161 | uimenu(hef,'Label','New User Fit...','Separator','on','Callback','editfit');
|
---|
162 | uimenu(hef,'Label','Reset','Separator','on','Callback',...
|
---|
163 | 'if strcmp(questdlg(''Are you sure you want to reset the user defined fits?'',''Reset User Fits'',''No''),''Yes''), delete(''userfit.mat''); efmenu; end');
|
---|
164 |
|
---|
165 |
|
---|
166 | % remainder of the menu:
|
---|
167 | uimenu(h,'Label','Refresh EzyFit menu','Callback','efmenu');
|
---|
168 | uimenu(h,'Label','Edit Fit Coefficients','Callback','editcoeff');
|
---|
169 | uimenu(h,'Label','Show Fit Residuals','Callback','showresidual');
|
---|
170 |
|
---|
171 | uimenu(h,'Label','Get Slope','Separator','on','Callback','getslope(''equation'',''dialog'')','Accelerator','G');
|
---|
172 | uimenu(h,'Label','Show Slope...','Callback','showslope([],''dialog'')');
|
---|
173 |
|
---|
174 | hps=uimenu(h,'Label','Plot Sample','Separator','on');
|
---|
175 | uimenu(hps,'Label','Linear','Callback','plotsample linear');
|
---|
176 | uimenu(hps,'Label','Constant','Callback','plotsample cste');
|
---|
177 | uimenu(hps,'Label','3 polynomial curves','Callback','plotsample poly2');
|
---|
178 | uimenu(hps,'Label','Oscillations','Callback','plotsample osc');
|
---|
179 | uimenu(hps,'Label','Damped oscillations','Callback','plotsample damposc');
|
---|
180 | uimenu(hps,'Label','Exponential decay','Callback','plotsample exp');
|
---|
181 | uimenu(hps,'Label','Histogram with one peak','Callback','plotsample hist');
|
---|
182 | uimenu(hps,'Label','Histogram with two peaks','Callback','plotsample hist2');
|
---|
183 | uimenu(hps,'Label','Power law','Callback','plotsample power');
|
---|
184 | uimenu(hps,'Label','Power law with a cutoff','Callback','plotsample powco');
|
---|
185 |
|
---|
186 | hqc=uimenu(h,'Label','Axis','Separator','on');
|
---|
187 | uimenu(hqc,'Label','Swap X-axis lin <-> log','Callback','swx');
|
---|
188 | uimenu(hqc,'Label','Swap Y-axis lin <-> log','Callback','swy');
|
---|
189 | uimenu(hqc,'Label','Swap both X- and Y- axis','Callback','sw','Accelerator','B');
|
---|
190 | uimenu(hqc,'Label','Include the origin','Callback','axis0');
|
---|
191 | uimenu(hqc,'Label','Center the origin','Callback','axisc');
|
---|
192 | uimenu(hqc,'Label','Enlarge to nearest power of 10','Callback','axisl');
|
---|
193 |
|
---|
194 | uimenu(h,'Label','Edit Default Settings...','Separator','on','Callback','edit fitparam');
|
---|
195 | uimenu(h,'Label','Help EzyFit','Callback','docezyfit');
|
---|
196 | uimenu(h,'Label','Check for update','Callback','checkupdate_ef(''dialog'')');
|
---|
197 | uimenu(h,'Label','EzyFit Home Page','Callback','web http://www.fast.u-psud.fr/ezyfit -browser');
|
---|
198 | uimenu(h,'Label','About EzyFit','Callback','about_ef(''dialog'')');
|
---|
199 | end
|
---|
200 | otherwise
|
---|
201 | error('Unknown option');
|
---|
202 | end
|
---|
203 |
|
---|
204 |
|
---|
205 | % -----------------------------------------
|
---|
206 | % Subfunction 'efmenu install'
|
---|
207 |
|
---|
208 |
|
---|
209 | function install_ef
|
---|
210 |
|
---|
211 | % This location no longer works for Windows 7:
|
---|
212 | %sufile = fullfile(matlabroot,'toolbox','local','startup.m');
|
---|
213 |
|
---|
214 | sufolder = strrep(userpath,';','');
|
---|
215 | sufolder = strrep(sufolder,':',''); % new v1.81, thanks J. Bagrow
|
---|
216 | sufile = fullfile(sufolder,'startup.m');
|
---|
217 |
|
---|
218 | ft = [];
|
---|
219 | if exist(sufile,'file')
|
---|
220 | try
|
---|
221 | ft = textread(sufile,'%s');
|
---|
222 | catch
|
---|
223 | ft = [];
|
---|
224 | end
|
---|
225 | end
|
---|
226 | if ~isempty(ft)
|
---|
227 | for num = 1:length(ft)
|
---|
228 | if strfind(ft{num},'efmenu'),
|
---|
229 | disp('The EzyFit menu is already installed in your startup.m file:');
|
---|
230 | disp(sufile);
|
---|
231 | return
|
---|
232 | end
|
---|
233 | end
|
---|
234 | %copyfile(sufile,fullfile(matlabroot,'toolbox','local','startup_previous.m'));
|
---|
235 | copyfile(sufile,fullfile(sufolder,'startup_previous.m'));
|
---|
236 | fid=fopen(sufile,'a');
|
---|
237 | fprintf(fid,'%s\n',' ');
|
---|
238 | fprintf(fid,'%s\n',['% These lines have been added by ''efmenu install'' (' datestr(now) '):']);
|
---|
239 | fprintf(fid,'%s\n','efmenu; % Includes the EzyFit menu for all new figure.');
|
---|
240 | fprintf(fid,'%s\n\n','fprintf('' To get started with the EzyFit toolbox, select <a href="matlab:docezyfit">EzyFit</a> from the Help browser.\n\n'');');
|
---|
241 | fclose(fid);
|
---|
242 |
|
---|
243 | disp('The EzyFit menu has been correctly installed.');
|
---|
244 | disp('To get started, select <a href="matlab:docezyfit">EzyFit</a> from the Help browser.');
|
---|
245 |
|
---|
246 | else % creates a new startup.m file and re-calls install_ef:
|
---|
247 | fid=fopen(sufile,'w');
|
---|
248 | fprintf(fid,'%s\n','%STARTUP Startup file');
|
---|
249 | fprintf(fid,'%s\n','% This file is executed when MATLAB starts up.');
|
---|
250 | fprintf(fid,'%s\n',' ');
|
---|
251 | fclose(fid);
|
---|
252 | install_ef;
|
---|
253 | end
|
---|