Error: Undefined function 'variable' for input arguments of type 'char'

Every now and then when my algortihm calls the cvx I get this error. (The one on the title)
It doesn’t always display the error, only sometimes. If I re-run the algorithm once again it will most likely not display the message again.

It points to the line where I declare the variable on cvx, such as
variable x(n)
Judging by the message it seems matlab doesn’t recognize that I’m on cvx environment for some reason even though I called cvx_begin on the previous line. Yeah, I’m sure I did the correct sintax because once again, if I re-run it turns out well.

Basically re-running solves the problem, however I never know when I’m gonna get the error again and if I call cvx a lot of times inside an algorithm the risk of getting this error raises…

Any idea of why does this happen?

That’s a very interesting issue, and I am afraid I don’t know what’s going on. I hope someone can help us identify a clear, reproducible case when it occurs.

I do have something to try. When you’re running one of your codes that does occasionally cause this error, try running cvx_setpath before the code begins.

CVX does some MATLAB path manipulation after in cvx_begin and cvx_end so that certain keywords like variable are not present in your path when not using CVX. Typing cvx_setpath just forces CVX to leave them in there permanently.

It’s possible MATLAB is not refreshing its path reliably in the middle of execution, and if that’s the case, this should fix it.