MATLAB: In a constrained optimization if “beq” is a matrix with a variable, then how to plot the variable in “beq” and the objective function

fminconplot

I want to have plot of variable (m) value and objective function values (-fval) in "x","y" axis respectively, I can evaluate the values of "fval" but can't plot the desired results.
Following is my working programme:
fun = @(x)sum((x.*(log(x))));
A = [];
b = [];
x0 = [1/6 1/6 1/6 1/6 1/6 1/6];
lb = [0,0,0,0,0,0];
ub = [1,1,1,1,1,1];
Aeq = [1,1,1,1,1,1;1,2,3,4,5,6];
for m=1:0.5:6;
beq = [1;m];
[x,fval] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub);
plot(m,-fval);
end

Best Answer

You are not saving all the values of fval. Try this
fun = @(x)sum((x.*(log(x))));
A = [];
b = [];
x0 = [1/6 1/6 1/6 1/6 1/6 1/6];
lb = [0,0,0,0,0,0];
ub = [1,1,1,1,1,1];
Aeq = [1,1,1,1,1,1;1,2,3,4,5,6];
m=1:0.5:6;
fval = zeros(1, numel(m));
for ii=1:numel(m)
beq = [1;m(ii)];
[x,fval(ii)] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub);
end
plot(m,-fval);