Error with nlinfit and it said Index exceeds the number of array elements (1)
5 ビュー (過去 30 日間)
古いコメントを表示
I just start learing how to use Matlab, and I was trying to run the nlinfit like this:
ogfun = @(var,x) 1./(1+exp(-(var(1)+var(2)*x)));
var=[1;1]; x=(-10:1:10);
y=logfun(var,x);
plot(x,y);
K>> beta=nlinfit(x,y,logfun,1)
Then it gave me an error said "Error using nlinfit (line 213)
Error evaluating model function '@(var,x)1./(1+exp(-(var(1)+var(2)*x)))'.
Caused by:
Index exceeds the number of array elements (1)."
I know it's a silly question but can anyone tell me why it said that index exceeds the number of array elements and what (1) stands for?
0 件のコメント
回答 (1 件)
Rajanya
2024 年 11 月 26 日 12:18
I have been able to reproduce the issue at my end and the error is because the function ‘nlinfit’ demands its ‘beta0’ argument (initial parameter values) to be a vector. Here, 1 is being passed which is interpreted as a scalar. Consequently, when the ‘logfun’ function is evaluated, attempting to access ‘var(2)’ results in this error.
Modifying the ‘nlinfit’ call as shown below resolves the error.
beta = nlinfit(x,y,logfun,[1 1])
To know more about ‘nlinfit’ and its usages, you can refer to the documentation page by executing the following command from the MATLAB Command Window:
doc nlinfit
Hope this helps!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!