Cannot use a value of type struct as an index

This is my first time using CVX with Gurobi to solve a problem.And I want to see how it works with a simple example. The following is the example that I am trying:

% Matlab code
m=1
cvx_begin
    variable x(1)
    minimize( x(1) )
    subject to
        2<=x(1)
cvx_end

However, I got the error ‘Cannot use a value of type struct as an index.’, and additional info is as followed:

Calling Gurobi 9.00: 1 variables, 1 equality constraints
------------------------------------------------------------
------------------------------------------------------------
Status: Error
Optimal value (cvx_optval): NaN

Cannot use a value of type struct as an index.

Error cvxprob/solve (line 435)
             [x, status, tprec, iters] = shim.solve( At, b, c, cones, quiet, prec, solv.settings, eargs{:} );

Error cvx_end (line 88)
         solve( prob );

Error ArrayDesignTst (line 51)
cvx_end

Is there any way to fix this issue? Thanks!

1 Like

Does this execute without error using a different solver than Gurobi?

There may be some bugs in the Gurobi-CVX interface.

My only suggestions: Use CVX 2.2, not CVX 3.0beta. Try reinstalling CVX. Try a fresh MATLAB session. Try a different (more recent) version of Gurobi.

1 Like

I restarted my Matlab2020a and tried four solvers, and this example worked well with all solver except Gurobi. So i think maybe there is some bug in the CVX-Gurobi interface.By the way, I’m using the standard CVX2.2.But i dont know whether latest version of Gurobi fits the CVX, cause when i install a Gurobi license, the grbkey version is 9.0.0

1 Like

I had the exact issue. It appears cvx_solver default setting are currently
assigned to ‘SDPT-3’. You need to change your cvx_solver to ‘sedumi’
and the issue is resolved. I have not figure out as to why cvx_solver default of 'SDPT-3"
is triggerring this error but will leave it to the developer for correction.
Hope this is helpful.

Supra