Clear Filters
Clear Filters

Function 'subsindex' is not defined for values of class 'struct'.

1 view (last 30 days)
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 Comments
Matt J
Matt J on 11 Mar 2013
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
Eric Sirott on 25 May 2016
nope, I've had the same problem and I too was perplexed when there wasn't a line number.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 10 Mar 2013
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 Comments
Bestun
Bestun on 10 Mar 2013
Dear Walter Thanks for you answer Gurobi is a solver could be used in Matlab. What did you say seems reasonable, but I am still getting the same problem
Walter Roberson
Walter Roberson on 11 Mar 2013
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

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!