Expression error


My model has a multi-dimensional variable x(m,n,p) and another multi-dimensional expression f(m,n,p). However, when I initialize f and compute f as linear/affine function of x, I still got the same error from Matlab for not using expression. My code is as follows:
variable x(m,n,p);
expression f(m,n,p);

f = zeros(m,n,p);
for i=1:m
for j = 1:n
for k = 1:p
f(i,j,k) = f(i,j,k) + x(a(i),b(j),c(k))/d;

where a(.), b(.), c(.) are some transformation of indices and d is a constant. The Matlab error is
The following error occurred converting from cvx to double:
Error using double
Conversion to double from cvx is not possible.

Do you know what the problem is here?

Yes, when you type this

f = zeros(m,n,p)

you are replacing the CVX expression f with a numeric matrix. And you can’t assign a CVX expression to an element of a numeric matrix. Delete that line and you should be fine.

Thanks Michael,