Getting error Unable to perform assignment because dot indexing is not supported for variables of this type
2 ビュー (過去 30 日間)
古いコメントを表示
I'm getting the following error:
"Unable to perform assignment because dot indexing is not supported for
variables of this type.
Error in fminunc (line 225)
options.GradObj =
optimget(options,'GradObj',defaultopt,'fast',allDefaultOpts);
Error in optimization (line 16)
[theta,R,exitflag,output,grad,hessian]=fminunc('pb',theta0,R0,options,A); "
This happens when I run this code:
A = importdata('C:code\data.asc');
options=optimset('Display','off','MaxIter',10000,'TolX',10^-30,'TolFun',10^-30);
theta0 = -1;
R0 = -3;
[theta,R,exitflag,output,grad,hessian]=fminunc('pb',theta0,R0,options,A); %this is line 16
theta
R
hessian^-1
A is my data (two columns) and I use it in 'pb' when I call it:
function neg_lik = pb(V_0, V_1, A)
A = importdata('C:code\data.asc');
and at the end:
lik = 1;
for i = 1:1000
lik = A(i, 2)*(1 - 1/( 1 + exp(V_1(A(i, 1), 1) - V_0(A(i, 1), 1)))) + (1 - A(i, 2))/(1 + exp(V_1(A(i, 1), 1) - V_0(A(i, 1), 1)));
lik = li * li_contribution;
end
neg_lik = -1 * lik;
How can I solve this problem?
I tried loading the data and creating a matrix instead of importing it but keep getting the same error message. I'm using Matlab R2019
0 件のコメント
採用された回答
Walter Roberson
2019 年 7 月 18 日
You cannot skip arguments to fmincon (except for one near the end). Before you pass in options you need to pass in
objective x0 A b aeq beq lb ub nonlcon
And then you can pass in options.
You also need to learn how to parameterize your function. And your x0 needs to be the same size as what needs to be found, which appears to be theta and R, but you do not use theta or R in your function...
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!