sinpen 发表于 2015-4-12 15:54

【fittype问题】fittype接受的匿名函数中带有阶乘相,MATLAB提示错误

先贴代码:t = 1:1:11;
h = ;
plot(t, h, 'or'), hold on

s = fitoptions('Method', 'LinearLeastSquares');

ffun = fittype(@(lambda,n)(((lambda.^n)./factorial(n)).*exp(-lambda)),...
    'Coefficients', {'lambda'},...
    'Independent', 'n'...
    );

= fit(t', h', ffun,...
    'StartPoint', );

plot(cfun,'b')这段script运行到 fittype 函数这里,会提示说传入的函数句柄为不可计算的MATLAB表达式:Error using fittype (line 356)
Expression (((lambda.^n)./factorial(n)).*exp(-lambda)) is not a valid MATLAB expression, has non-scalar coefficients,
or cannot be evaluated:
Error while trying to evaluate FITTYPE function :

N must be a matrix of non-negative integers.

Error in poissonFit (line 7)
ffun = fittype(@(lambda,n)(((lambda.^n)./factorial(n)).*exp(-lambda)),...
但是,我直接将这个函数句柄拿出来用,是可以加算的。

sinpen 发表于 2015-4-12 16:07

我深深地怀疑是不是那个factorial阶乘并不适合使用fittype?
页: [1]
查看完整版本: 【fittype问题】fittype接受的匿名函数中带有阶乘相,MATLAB提示错误