Function 'subsindex' is not defined for values of class 'struct'.
조회 수: 1 (최근 30일)
이전 댓글 표시
Dear All This is a part of my code
if gurobi
clear prob
prob.obj=full(obj);
prob.A=equalityMatrix;
prob.rhs=full(equalityRHS);
prob.sense=['='];
prob.lb=full(lowerB);
prob.up=full(upperB);
params.Method=2;
params.Crossover=0;
params.outputflag = 0;
res = gurobi(prob, params);
if ~strcmp(res.status,'OPTIMAL')
disp(res.status);
end
solution=res.objval;
variables=res.x;
When I am running it I get this error: Function 'subsindex' is not defined for values of class 'struct'.
could you please inform me how to fix this problem
댓글 수: 4
Matt J
2013년 3월 11일
No, it can't be the whole thing. For example, the code below results in the error message
Error using subsindex
Function 'subsindex' is not defined for values of class 'struct'.
Error in test (line 10)
gurobi(prob,params);
Notice that it includes a line number and the specific statement that triggered the error.
gurobi=1;
params.Method=2;
params.Crossover=0;
params.outputflag = 0;
prob=params;
gurobi(prob,params);
Eric Sirott
2016년 5월 25일
nope, I've had the same problem and I too was perplexed when there wasn't a line number.
답변 (1개)
Walter Roberson
2013년 3월 10일
Your first line,
if gurobi
implies that gurobi is more likely a variable than a function. But later you have the line
res = gurobi(prob, params);
where prob and params are struct. If gurobi is a variable there, then you are trying to use the struct as indices, which MATLAB would give an error message for (the one you are seeing.)
In order for gurobi to be a function, then for it to be consistent with "if gurobi", then it would be necessary for it to be possible to invoke gurobi with no parameters (instead of with two parameters). That is possible, but if that is your intent then it would be clearer for readers if you were to write
if gurobi()
댓글 수: 2
Walter Roberson
2013년 3월 11일
At the MATLAB command line, enter the command
dbstop if error
then run your program. When it stops, show us which line it stopped on, and also please show us the result of
which -all gurobi
and
whos gurobi
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!