Error: undefined function or variable 'varname'


I wrote a simple piece of cvx code.

variable x(n);
variable z(n);
variable w(n);
expression s;
expression alk;
expression hrk;
alk   = x'*A*x;  %A and B are positive semidefinite matrices
hrk   = s'*B*s;

minimize (1/(2*lambda)*alk+1/(2*lambda_o)*hrk-ONESn'*x)
subject to 
     x >=0
     z     >=0
     w     >=0
     x  <= 1/n

But unfortunately, this code produces the following error

Undefined function or variable 'x'.

Error in twofuncsvm (line 19)

When I change the variable name to some other thing say u, for the first time the error is about other variables like z or w and after some times again the error is about u .
What is the problem, what I’m doing wrong?
Any help is appreciated. I don’t know what to do.

(Michael C. Grant) #2

Do you have a file named ‘x.m’ anywhere in your MATLAB path?

(Michael C. Grant) #3

Also, you don’t happen to be running R2015b prerelease? If so… don’t. :slight_smile:


Hi. No I don’t have any file with that name. Even I change variable name to some other thing say ‘alp’, after some times I got the same error. And no, my matlab version is (R2014a). This is not the first time I use cvx with this computer. I wonder what to do?

(Michael C. Grant) #5

I must be honest I’m stumped. Makes no sense to me that right after declaring the variables they no longer exist. Without access to your computer there’s no way I can debug it. I’d suggest completely removing and reinstalling CVX but that seems weak.


When I bring mouse over the cvx variable, matlab intellisense shows something like ‘cvx variable 18*1’. But right after that error occurred.

(Michael C. Grant) #7

That’s just crazy. I do apologize but of course I can’t reproduce the issue here!

(Sara Hesami) #8

I have the same problem here now!