Anonymous functions in cftool GUI
이전 댓글 표시
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
채택된 답변
추가 답변 (2개)
Joe V
2013년 9월 28일
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).)
Marcelo Alcocer
2014년 9월 2일
카테고리
도움말 센터 및 File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!