First,I can't get the result, so I think the problem  has too many  circulations,but the matlab  run the  "ObjValue=Obj1+Obj2;" Elapsed time is 204.072802 seconds., however if I put the d instead of the y0,y1,mult,the matlab will run fast.Obviously,the  sdpvar in yalmip affect the effcet, when I wait 4 minutes ,it run the solversdp,but it says Error using eig ,Out of memory.  Error in lmi/categorizeproblemÂ
[-M1*b <= c <= M1*b, -M2*(1-b) <= c-a <= M2*(1-b)]
  for r=1:M
      if r~=j
        qq(r)=q(r)*y0(i,r);
      end
    endQQ = sdpvar(length(q));
for i=1:M Â Â
  for j=1:M Â
    qq = q'.*y0(i,:);qq(j) = 0;
    QQ(i,j) = sum(qq); Â
  end  Â
end
H = repmat(h,1,length(h));
Q = repmat(q',length(q),1);
Obj1fast = sum(sum((H.*d.*(1-Q) + mult).*y0));
Obj2fast = sum(sum((H.*d.*QQ + mult).*y1));H.*d.*QQ).* y1, mult.*y1 etc. Very straightforward to do, use precisely the linearization strategy I explained above, but in a matrix format.
In your code qq(r) will be q(j-1)*y0(i,j-1) when r = j and j>1 (since you never clear qq, so qq is occupied with data from last loop)clc;clear all;ticload data[m,n]=size(d);M=n;y0=binvar(m,n,'full');y1=binvar(m,n,'full');mult=sdpvar(m,n,'full');QQ = sdpvar(length(q));
for i=1:M      for j=1:M       qq = q'.*y0(i,:);    qq(j) = 0;    QQ(i,j) = sum(qq);    end   end
toc[-M1*b <= c <= M1*b, -M2*(1-b) <= c-a <= M2*(1-b)]H.*d.*(1-Q) TIMES y0
mult TIMES y0
H.*d.*QQ TIMES y1
mult TIMES y1
I.e, 4 * (M^2) logical models
tic
QQ = [];
for i=1:M
  Qrow = [];
  for j=1:M Â
    qq = q'.*y0(i,:);
    qq(j) = 0;   Â
    Qrow = [Qrow sum(qq)];
  end  Â
  QQ = [QQ;Qrow];
end
toc
tic
QQ2 = [];
for i=1:M Â Â
  Qrow = sum(q'.*y0(i,:))-q'.*y0(i,:);    Â
  QQ2 = [QQ2;Qrow];
end
toc
tic
QQ3 = repmat(sum(repmat(q(:)',M,1).*y0,2),1,M)-repmat(q(:)',M,1).*y0
toc
clc;clear all;load data[m,n]=size(d);M=n;d_ave = sum(sum(d))/(M*M);mult = repmat(h*d_ave/10,1,M)y0=binvar(m,n,'full');y1=binvar(m,n,'full');
QQ = [];for i=1:M     Qrow = sum(q'.*y0(i,:))-q'.*y0(i,:);        QQ = [QQ;Qrow];endH = repmat(h,1,length(h));Q = repmat(q',length(q),1);Obj1fast = sum(sum((H.*d.*(1-Q) + mult).*y0));% a*b where b is binary is replaced with continuous variable c, and the constraints%  [-M1*b <= c <= M1*b, -M2*(1-b) <= c-a <= M2*(1-b)]M1=1;M2=1;c=semivar(m,n);%c=sdpvar(m,n);Obj2fast = sum(sum((H.*d.*QQ + mult).*c));ObjValue = obj1fast + obj2fast ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Constraints = [];for i = 1:M  Constraints = [Constraints, sum(y0(i,:)) == 1,sum(y1(i,:)) == 1];end% Constraints = [Constraints,mult >= 0];Constraints = [Constraints, -M1*y1 <= c <= M1*y1, -M2*(1-y1) <= c-H.*d.*QQ <= M2*(1-y1)];
sum(sum((H.*d.*QQ_TIMES_Y1 + mult.*y1));[-M1*b <= c <= M1*b, -M2*(1-b) <= c-a <= M2*(1-b)]
[something+c <= 0, -M1*b <= c <= M1*b, -M2*(1-b) <= c-a <= M2*(1-b)]