An error with new function defined by myself, what does it mean?

function f=loss_fun(W,a,S,M,X,Y,C,N)
%S is the variable(3d tensor), other inputs are parameters given
f=0;

for n=1:N

    for c=1:C

        sum=zeros(X,Y);

        for m=1:M

            sum=sum+a(m,c,n)*S(:,:,m);

        end

        f=f+power(norm(W(:,:,c,n)-sum),2);

    end

end

end

this function is defined by myself and to be minimize. The function is surely convex. But there is an error : Undefined function ‘sparse’ for input arguments of type ‘single’. What does this error mean?

That doesn’t sound like a CVX-specific error. You will have to provide more detail of the error to get help. Also, watch that use of the power function; it violates the DCP rules; use pow_pos instead.