MATLAB: Please help me !!Dimensions of matrices being concatenated are not consistent.

error using vertcatfsolve

Error using vertcat Dimensions of matrices being concatenated are not consistent.
Error in mypaper/myfun (line 47) y = [a+b*(1-a)-x,
Error in fsolve (line 241) fuser = feval(funfcn{3},x,varargin{:});
Error in mypaper (line 5) y = fsolve(@myfun,z0,options);
Error in testMypaper (line 15) x = mypaper(p,min,n,m,N,L);
Caused by: Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
function [y] = mypaper(p,min,n,m,N,L)
z0 = [0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1];
options = optimset('Display','off');
y = fsolve(@myfun,z0,options);
function y = myfun(z);
b0 = z(1);
a = z(2);
b = z(3);
x = z(4);
pidle = z(5);
lis1 = z(6);
lis2 = z(7);
ptx = z(8);
pco = z(9);
Pc = z(10);
pback1 = z(11);
pback2 = z(12);
y = [a+b*(1-a)-x,
((1-b)*(1-a)*((1-x^(m+1))/(1-x)) + x^(m+1))*b0/p - pidle,
((1-x^(m+1))/(1-x))*b0 - lis1,
(1-a)*((1-x^(m+1))/(1-x))*b0 - lis2,
1-(1-lis1)^(N-1) - Pc,
(1-Pc)*(1-b)*(1-a)*((1-x^(m+1))/(1-x))*b0 - ptx,
Pc*(1-b)*(1-a)*((1-x^(m+1))/(1-x))*b0 - pco,
((2^(min+n)+1)/2)*((x^n-x^(m+1))/(1-x))*b0 - pback2,
((1-x^(n+1))/(1-x) + 2^min*((1-(2*x)^(n+1))/(1-2*x)))*b0/2 - pback1,
L*Pc*(1-a)*(1-b) - a,
(1- 1/(1+1/(1-(1-lis1)^N)))*(1-(1-lis1)^N) -b,
pidle + ptx + pco + pback2 + pback1 - 1];
end
end
v = 0.2; N = 5; p = v/N; min = 3; n = 5; m = 7; L = 5; x = mypaper(p,min,n,m,N,L);
thank you for you help

Best Answer

One of those lines that comprise y is not a scalar. Check each term one by one to see which is not a scalar.
term = a+b*(1-a)-x;
term = ((1-b)*(1-a)*((1-x^(m+1))/(1-x)) + x^(m+1))*b0/p - pidle;
term = ((1-x^(m+1))/(1-x))*b0 - lis1;
term = (1-a)*((1-x^(m+1))/(1-x))*b0 - lis2;
term = 1-(1-lis1)^(N-1) - Pc;
term = (1-Pc)*(1-b)*(1-a)*((1-x^(m+1))/(1-x))*b0 - ptx;
term = Pc*(1-b)*(1-a)*((1-x^(m+1))/(1-x))*b0 - pco;
term = ((2^(min+n)+1)/2)*((x^n-x^(m+1))/(1-x))*b0 - pback2;
term = ((1-x^(n+1))/(1-x) + 2^min*((1-(2*x)^(n+1))/(1-2*x)))*b0/2 - pback1;
term = L*Pc*(1-a)*(1-b) - a;
term = (1- 1/(1+1/(1-(1-lis1)^N)))*(1-(1-lis1)^N) -b;
term = pidle + ptx + pco + pback2 + pback1 - 1;
One of those will not be the same size as the others. Use the debugger to find out which term it is.