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

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 commentaires

Copy/paste the full error message.
Dear Math this is the whole error message
Function 'subsindex' is not defined for values of class 'struct'.
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);
nope, I've had the same problem and I too was perplexed when there wasn't a line number.

Connectez-vous pour commenter.

Réponses (1)

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 commentaires

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
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

Connectez-vous pour commenter.

Catégories

Question posée :

le 10 Mar 2013

Commenté :

le 25 Mai 2016

Community Treasure Hunt

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

Start Hunting!

Translated by