Anonymous functions in cftool GUI
Show older comments
Does anyone know if it is possible to use anonymous functions in the custom equation box of the cftool GUI?
Simply typing them in results in an error in R2012a, e.g.
@(x,tau) exp(-t/tau)
Expression @(x,tau) exp(-t/tau) is not a valid MATLAB expression, has non-scalar coefficients, or cannot be evaluated:
Undefined function 'imag' for input arguments of type 'function_handle'.
My motivation is to use anonymous functions as arguments of a custom fitting function to be called by cftool, e.g.:
MyCustomFitFunction(x,hFun1,hFun2,FitParam1,FitParam2)
with hFun1 and hFun2 as function handles.
I imagine this is very possible using the non-interactive fitting tools, but was keen on using the GUI.
Thanks
Accepted Answer
More Answers (2)
Joe V
on 28 Sep 2013
You don't need to use an anonymous function. Just type in your function, making sure to use x as the independent variable:
exp(-x/tau)
The Curve Fitting Tool will recognize x as the independent variable and tau as a parameter of the fit. (If the curve you want to fit to is literally exp(-x/tau), you might not need a custom equation -- the Exponential fit type will fit to the curve a*exp(b*x).)
1 Comment
Marcelo Alcocer
on 28 Sep 2013
Marcelo Alcocer
on 2 Sep 2014
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!