1 | function editfit(n,name,eq)
|
---|
2 | %EDITFIT Edit a user defined fit
|
---|
3 | % EDITFIT edit a new user defined fit.
|
---|
4 | %
|
---|
5 | % EDITFIT(N) edits the fit #N.
|
---|
6 | %
|
---|
7 | % EDITFIT(N,NAME,EQ) sets the name NAME and the equation EQ of the user
|
---|
8 | % defined fit #N.
|
---|
9 | %
|
---|
10 | % EDITFIT('reset') deletes the user defined fits.
|
---|
11 | % EDITFIT('list') lists the user defined fits
|
---|
12 | %
|
---|
13 | % Example: editfit(3,'myexp','a*exp(-x/tau); a=0.1; tau=100;');
|
---|
14 | %
|
---|
15 | % See also LOADFIT, EFMENU, EZFIT.
|
---|
16 |
|
---|
17 | % F. Moisy, moisy_at_fast.u-psud.fr
|
---|
18 | % Revision: 1.20, Date: 2006/02/02
|
---|
19 | % This function is part of the EzyFit Toolbox
|
---|
20 |
|
---|
21 | % History:
|
---|
22 | % 2006/01/12: v1.00, first version.
|
---|
23 | % 2006/01/19: v1.10, syntax changed. Now does not ask for the fit number.
|
---|
24 | % 2006/02/02: v1.20, use a new mat-file for user defined fits
|
---|
25 |
|
---|
26 |
|
---|
27 | % directory where the ezyfit toolbox is installed:
|
---|
28 | efroot=fileparts(mfilename('fullpath'));
|
---|
29 | userfitfile=[efroot filesep 'userfit.mat'];
|
---|
30 |
|
---|
31 | % option 'reset' or 'list':
|
---|
32 | if (nargin==1) && (~isnumeric(n))
|
---|
33 | if strcmp(n,'reset'),
|
---|
34 | clear userfit;
|
---|
35 | if exist(userfitfile,'file'),
|
---|
36 | delete(userfitfile);
|
---|
37 | end;
|
---|
38 | loadfit('user');
|
---|
39 | return;
|
---|
40 | elseif strcmp(n,'list'),
|
---|
41 | userfit=loadfit('user');
|
---|
42 | for i=1:length(userfit),
|
---|
43 | disp(['Fit #' num2str(i) ': ' userfit(i).name]);
|
---|
44 | disp([' ' userfit(i).eq]);
|
---|
45 | end;
|
---|
46 | return;
|
---|
47 | end;
|
---|
48 | end;
|
---|
49 |
|
---|
50 | userfit=loadfit('user');
|
---|
51 |
|
---|
52 | % 3 arguments: sets the fit #n to its new definition.
|
---|
53 | if (nargin==3),
|
---|
54 | if n<=(length(userfit)+1),
|
---|
55 | userfit(n).name=name;
|
---|
56 | userfit(n).eq=eq;
|
---|
57 | save(userfitfile,'userfit');
|
---|
58 | efmenu; % refresh the ezyfit menu
|
---|
59 | return;
|
---|
60 | else
|
---|
61 | error('Wrong fit number.');
|
---|
62 | end;
|
---|
63 | end;
|
---|
64 |
|
---|
65 |
|
---|
66 | % no argument: creates a new fit.
|
---|
67 | if (nargin==0)
|
---|
68 | n=length(userfit)+1;
|
---|
69 | userfit(n).name = ['fit' num2str(n)];
|
---|
70 | userfit(n).eq = 'a*x+b*x^2 ; a=1 ; b=0.1';
|
---|
71 | end;
|
---|
72 |
|
---|
73 | if n>length(userfit),
|
---|
74 | error('Wrong fit number.');
|
---|
75 | end;
|
---|
76 |
|
---|
77 | answer = inputdlg({'Name (enter an empty string to delete this fit):',...
|
---|
78 | 'Equation y(x) = a*x + b*x^2...; a=1; ...'},...
|
---|
79 | ['Edit User Fit #' num2str(n)], 1,...
|
---|
80 | {userfit(n).name,userfit(n).eq});
|
---|
81 |
|
---|
82 | if ~isempty(answer)
|
---|
83 | if isempty(answer{1}), % deletes this fit
|
---|
84 | userfit = userfit([1:(n-1) (n+1):end]);
|
---|
85 | else
|
---|
86 | userfit(n).name=answer{1};
|
---|
87 | userfit(n).eq=answer{2};
|
---|
88 | end;
|
---|
89 | save(userfitfile,'userfit');
|
---|
90 | efmenu; % refresh the ezyfit menu
|
---|
91 | else
|
---|
92 | return;
|
---|
93 | end;
|
---|
94 |
|
---|