Anonymous functions in cftool GUI
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (2)
Joe V
el 28 de Sept. de 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 comentario
Marcelo Alcocer
el 28 de Sept. de 2013
Marcelo Alcocer
el 2 de Sept. de 2014
Categorías
Más información sobre Get Started with Curve Fitting Toolbox en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!