Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using fit, fittype, fitoptions

100 views
Skip to first unread message

Michael

unread,
Dec 22, 2009, 7:26:03 AM12/22/09
to
Hi Everyone,

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 Lane

unread,
Dec 22, 2009, 11:43:59 AM12/22/09
to
> s = fitoptions('Method','NonlinearLeastSquares',...
...

> Error in ==> dayswithoutsunspots at 24
> f =
>
> fittype('a*tanh(b*x)','coefficients',{'a','b'},'independent','x','options','s');
>
Michael, you want to pass in the variable s, not its name 's'.

-- Tom


Michael

unread,
Dec 22, 2009, 12:18:20 PM12/22/09
to
"Tom Lane" <tl...@mathworks.com> wrote in message <hgqt0f$qu9$1...@fred.mathworks.com>...

Thanks Tom that helped... guess I followed one of the examples too blindly :-)

Sincerely
Michael

0 new messages