MATLAB: Output argument “a” (and maybe others) not assigned during call to

output argument not assigned

I get this error message when running the code, 'Output argument "a" (and maybe others) not assigned during call to…MH'. But 'a' is exactly in the output from function MH, plus, if I run the codes for each j, it works fine, only when I run the loop, this error message comes out. Where do I get wrong?
for i=2:N
x = xdraw(i-1, :);
for j = 1:5
new = normrnd(x(j), sigma(j));
[x a] = MH(x,j,new,y,sigma);
acc_x(j)=acc_x(j)+a;
end
xdraw(i, :) = x;
end

Best Answer

You gave the calling routine, but for some reason you forgot to give MH, which is the most crucial code we need to see. Most likely you didn't initialize "a" and only assigned it inside a block of code that is not getting run, for example inside an "if" block.
Related Question