MATLAB: How to solve “Index exceeds matrix dimensions” error..

errorexceedmatrix

Hi everyone.. can any one please help me with this error my code is as follow. i am getting error for Pi value.
%%%---- fraction of time wifi channel is idle
t= 2./(W+1);
p=1-(1-t).^(n-1);
B100=2*(1-2*p)*(1-p)./(1-2*p)*(W+1)+(p*W)*(1-(2*p)^m);
ti=0.1;
tb=0.2;
p0=1-(1-ti).^(n-1);
p1=1-(1-tb).^(n-1);
for j=0:6
w=2^j.*(W);
end
for x=2:6
pi=prod(p1./w(x)+(p0./w(x)).*(w(x-1)-1));
end

Best Answer

In your loop
for j=0:6
w=2^j.*(W);
end
every iteration of your loop overwrites all of w, leaving it the same length as W. The result is going to be the same as if you had only executed the last iteration, when j is 6.
Then in the next loop, you try to index into w. If your W was not at least 6 items long, you are going to run off the end of your w
You probably want
for j=0:6
w(j+1) = 2^j .* (W);
end