필터 지우기
필터 지우기

Why doesn't fittype, in the curve fitting toolbox, see independent variable in input list of called function?

조회 수: 6 (최근 30일)
I want to use a fit model in the curve fitting toolbox complicated enough to warrant an m-file, but can't get fittype to recognize the independent variable. The same error is generated using the simple function given in the Help example:
>> g = fittype( @(a, b, c, x) a*x.^2+b*x+c )
g =
General model:
g(a,b,c,x) = a*x.^2+b*x+c
Suppose I name the model function:
>> f=@(a,b,c,x) a*x.^2+b*x+c
f =
@(a,b,c,x)a*x.^2+b*x+c
It evaluates nicely:
>> f(1,1,1,1)
ans =
3
but throws an error in fittype:
>> fittype( @(a, b, c, x) f)
Error using fittype>iAssertIsMember (line 1082)
*Independent variable x does not appear in the equation expression.*
Error in fittype>iTestCustomModelParameters (line 728)
iAssertIsMember( obj.indep, variables, 'curvefit:fittype:noIndependentVar' );
Error in fittype>iCreateFittype (line 370)
iTestCustomModelParameters( obj );
Error in fittype (line 328)
obj = iCreateFittype( obj, varargin{:} );
Naming the independent variable:
>> fittype( @(a, b, c, x) f,'independent','x')
gives the same error.
An m-file also gives the same error. I delete f, save f.m containing:
function ff = f(a,b,c,x)
ff = a*x.^2+b*x+c;
and execute:
>> fittype( @(a, b, c, x) f,'independent','x')
and get the same error as above.

답변 (2개)

Steven Lord
Steven Lord 2016년 9월 2일
See my response to your posting of this question in the newsgroup.
  댓글 수: 1
RAJEEV
RAJEEV 2023년 1월 27일
Dear Steve,
I am having same problem can you please elaborate the cause. The link you provided is no longer working.

댓글을 달려면 로그인하십시오.


Larry
Larry 2016년 9월 2일
편집: Matt J 2016년 9월 2일
fittype( @(a, b, c, x) f *(a,b,c,x)*)
works w/ f.m.

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by