How to get the sum of vector in CVX

C and Pi are vectors and have the same number of element.
min sigmaC§Pi§ +lamda||Pi*Pi||
s.t. Pi>=0 sigmaPi§=1
my code is below:

    sum_temp=0;
    n = viewNum;
    cvx_begin
        variable pi(n)
        minimize(c.*pi' + lamda*norm( pi, 2 ) )
        subject to
           pi>=0
           sum(pi) =1
    cvx_end

Matlab show the error is:
Error using subsindex
Function ‘subsindex’ is not defined for values of class ‘cvx’.
Error in multiview_NMF (line 123)
sum(pi) =1

You need to use == , not = , for equality constraint. So

sum(pi) == 1

Actually, I’m not sure why you are getting away with using pi as a variable name, because I received the error

Variable name "pi" is the name of a built-in MATLAB function.
Please choose a different name.

That is easily solved by changing the variable name, for instance to pii.

Yes, indeed. I don’t like having to have the reserved word check in my code, because it slows things down. But using names for CVX variables that coincide with built-in functions, or even user-defined functions in the MATLAB path, leads to really weird behavior.

Thank Mark L. Stone.I fix my code in you suggestion, but have the new error .

minimiz sigma(C§*pii§) +lamda||pii||2
subject to pii>=0
sigma(pii§)=1

my code is below:

clc
clear
viewNum = 3;
lamda =1e3;
pii(1,1:viewNum) = 1/viewNum*ones(1,viewNum);
disp('pii ' );
pii
size_pii = size(pii)
c(1,1)=2.17026938864275e-06;
c(1,2)= 1.78603303286262e-06;
c(1,3)=2.13626884759385e-06;
disp('c  ');
c
size_c = size(c)
cpii = c*pii'
n = viewNum;
cvx_begin
      variable pii(n)
       minimize(c*pii' + lamda*norm( pii, 2 ) )
       subject to
           pii >= 0
           sum(pii) ==1
cvx_end


Error using cvx/mtimes (line 41)
Inner matrix dimensions must agree.

It is strange,becuase cpii = c*pii’ is a right statment(c is 1 3, pii is 1 3 ,so cpii’=11,no proble),but in cvx,the sentence has error,why?

mcg has reformatted it in your new thread Matrix dimensions do not agree .

Yes, please learn to use the “code block” command in the editor. I’m going to delete your other post since this is just a continuation.

Use c*pii instead of c*pii'. pii is in fact 3x1.