フィルターのクリア

"Input argument is undefined" when using nlinfit

1 回表示 (過去 30 日間)
Gautam
Gautam 2014 年 5 月 27 日
コメント済み: Gautam 2014 年 5 月 28 日
Despite the variables all being defined in the workspace, implementation of the nlinfit function returns the error "Input argument p is undefined". The code I used follows:
fun = @(b,x,y,p) b(1).*x.*p.*((y/x).^b(2) - 1) + b(3)
b0 = [1 1 1];
mdl = nlinfit([x y p],q,fun, b0)
b0 gives the initial values for the coefficients to be determined - b1,b2,b3. fun is an anonymous function according to which the data is to be fit. x,y,p,q are all column vectors, which are visible in the workspace. Any help as to what is going on here would be greatly appreciated. Thank you very much in advance.
  2 件のコメント
Mahdi
Mahdi 2014 年 5 月 27 日
It looks like you don't have the variable p defined at all in your work space.
Mahdi
Mahdi 2014 年 5 月 27 日
If you already have y and p defined, why not simplify the problem and make it
fun=@(b,x) b(1).*x.*p.*((y/x).^b(2) - 1) + b(3)
b0=[1 1 1];
mdl=nlinfit(x,q,fun,b0)

サインインしてコメントする。

採用された回答

the cyclist
the cyclist 2014 年 5 月 27 日
Something like this?
x = rand(100,1);
y = rand(100,1);
p = rand(100,1);
q = rand(100,1);
M = [x y p];
fun = @(b,M) b(1).*M(:,1).*M(:,3).*((M(:,2)./M(:,1)).^b(2) - 1) + b(3)
b0 = [1 1 1];
mdl = nlinfit(M,q,fun, b0)
  3 件のコメント
the cyclist
the cyclist 2014 年 5 月 27 日
編集済み: the cyclist 2014 年 5 月 27 日
Because nlinfit is only passing one variable [the matrix I defined as M, (called "X" in the documentation)] to fun(). In the syntax you used, MATLAB has no way of knowing that the array
[x,y,p]
should be parsed into the three separate variables of your function.
Gautam
Gautam 2014 年 5 月 28 日
Oh, okay. Thank you very much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by