MATLAB: Eval inside arrayfun gives strange error

arrayfunevalfaq4.6MATLABscopevariable

Can someone explain why this doesn't work?
vec_1=[1 2 3 4];
vec_2=[5 6 7 8];
vec_3=[9 10 11 12];
vec_4=[13 14 15 16];
arrayfun(@(x)eval(sprintf('vec_%d',x)),1:4)
??? Error using ==> eval
Undefined function or variable
'vec_1'.
Error in ==>
@(x)eval(sprintf('vec_%d',x))
I'm just curious about this strange behavior, it says that vec_1 isn't defined but it is!
Thank you in advance
PS: This is related to http://www.mathworks.com/matlabcentral/newsreader/view_thread/303123 but I didn't get a reply, just a comment from someone acting like a douchebag.

Best Answer

If you put the function
function y = f(x)
y = eval(sprintf('vec_%d',x));
in a separate file and run the debugger, you'll find that vec_1, etc., are not in the scope of f(x). The same thing is probably true of the anonymous function.
EDIT: This works:
arrayfun(@(x) evalin('base',sprintf('vec_%d',x)),1:4)