Get decision variables from CVX in a matlab function

Dear friends,

I am trying to make an program where I can get the value of my decision variables from my optimization problem in CVX. Is it possible to do this? I have seen other functions that so far, have only make the problem run in CVX but this does not show any stored matrix of the problem…it just shows the problem running in the command window.

Example with a function that runs the CVX problem:

function optval=optim(input variables)
input variables
cvx_begin


cvx_end
end

I want to call my decision variables from the problem. How can I do this?

function decisionvariables=optim(input variables)
input variables
cvx_begin


cvx_end
end

Thank in advance for your help!

After cvx_end, presuming Status is solved, the CVX variables will be populated with their optimal values, and are available for any use in MATLAB, iincluding returning them from a MATLAB function which invokes CVX.

1 Like

Thank you!. I was not sure how the varible was actually saved after running the program. I tried it now and it works as:

[x,cvx_optval]=Optim6(PRU…)

where x is my decision variables in a vector and cvx optval is the value of the objective function.