I tried to use the cvx/sparse function to create a indicator matrix from the variable vector x (see below (full( sparse(1:n,x,1,n,k))).
cvx_begin
cvx_solver Mosek
variable x(n) integer
minimize( sum_square(freshape(full( sparse(1:n,x,1,n,k))’,nm,1)-B) )
subject to
A*x<=b
LB <= x <= UB
cvx_end
But I got the following error:
Error using cvx/sparse (line 25)
The first two arguments must be numeric.
The second argument in the cvx/sparse function is the cvx matrix “x”. Its elements are numeric. How can I solve this problem?
Besides, the third argument in the cvx/sparse function is a vector (in my example above, it’s a vector of all 1’s) rather than a structure. So I got the following error. How can I solve it?
Attempt to reference field of non-structure array.
Error in cvx/sparse (line 46)
[ ix, jx, vx ] = find( x.basis_ );
Thank you very much!