Im trying to fit a general hyperbolic tangent function to a dataset, here is the relevant code:
----------------------
M_tmp = CS{n,1}; % Extracts n'th column vector (this is the dataset)
s = fitoptions('Method','NonlinearLeastSquares',...
'Lower',[0,0],...
'Upper',[Inf,Inf],...
'Startpoint',[max(M_tmp)-0.1*max(M_tmp), 0]);
f = fittype('a*tanh(b*x)','coefficients',{'a','b'},'independent','x','options','s');
X = (1:length(M_tmp))';
cfun = fit(X,M_tmp,f)
----------------------
Now I have successfully fitted the above general expression in cftool and it works fine, but I would like Matlab to do it automatically on a series of datasets and this is where 'fit' comes in.
The chosen 'Method' is the same as in cftool, lower and upper bounds are the same and starting point is adjusted so fit should be able to do its work. The problem arises when I try to use 'options' in fittype I get the following error message:
------------------
??? Undefined function or method 'copy' for input arguments of type 'char'.
Error in ==> fittype.fittype>parseparams at 494
obj.fitoptions = copy( value );
Error in ==> fittype.fittype at 213
obj = parseparams(obj,{varargin{2:end}});
Error in ==> dayswithoutsunspots at 24
f =
fittype('a*tanh(b*x)','coefficients',{'a','b'},'independent','x','options','s');
-------------------
It is as though the function 'copy' does not exist in my Matlab installation. Now I have searched and found a number of built in functions in Matlab that has the function name copy, so I don't know whats going on here. Perhaps there is someone out there that has some experience using 'fit' and the associated 'fittype','fitoptions' that might be able to help.
Any help is appreciated. Thanks in advance! :-)
Sincerely
Michael Lindholm Nielsen
-- Tom
Thanks Tom that helped... guess I followed one of the examples too blindly :-)
Sincerely
Michael