I didn't want to overload with the code details, but many thanks for your support!
Please let me know if more explanations or other examples are needed.
%%The first part of the code is fmincon using YALMIP
x = sdpvar(1,24);
%This function puts the variables x in a new matrix that corresponds to the non-zero entries of SQ.
J = Joint(x,M);
%The following two functions return linear combinations of the variables x
YQ = MargYQ(squeeze(sum(J,3)),4,2);
Q_DUP = MargQ(YQ,2);
Constraints = [A*reshape(J,[1 256])' == b, x<ones(1,24), -x < zeros(1,24)];
assign(x,ones(1,24));
Obj = -kullbackleibler(reshape(YQ,[1,8]),Q_DUP) + sum(P.*reshape(J,[1 256]));
ops = sdpsettings('solver','fmincon','debug',1,'usex0',1);
ops.fmincon.TolCon = 1e-30;
ops.fmincon.TolFun = 1e-30;
ops.fmincon.TolFunValue = 1e-30;
ops.fmincon.TolFunValue = 1e-30;
optimize(Constraints,-Obj,ops)
x = value(x)
% In this part, the optimal objective is computed
J = Joint(x,M);
YQ = MargYQ(squeeze(sum(J,3)),4,2);
Q_DUP = MargQ(YQ,2);
Obj = -kullbackleibler(reshape(YQ,[1,8]),Q_DUP) + sum(P.*reshape(J,[1 256]));
R = Obj/log(2);
%This part of the code is the cvx implementation of the same problem
cvx_begin quiet
cvx_solver sedumi
variable x(24) nonnegative
J = Joint(x,M);
YQ = MargYQ(squeeze(sum(J,3)),4,2);
Q_DUP = MargQ(YQ,2);
maximize -sum(rel_entr(reshape(YQ,[1,8]),Q_DUP)) + sum(P.*reshape(J,[1 256]))
A*reshape(J,[1 256])' == b
cvx_end
RR = cvx_optval/log(2);
%The analytic solution for this problem (after division by log2) is log2(1+sqrt(5))-1
ERR_fmincon = abs(R-log2(1+sqrt(5))+1);
ERR_CVX = abs(RR-log2(1+sqrt(5))+1);