An ugly method to accomplish what you want
global a;
a = [1 2 3];
f = @() eval('global a; length(a)')
f()
a = [1 2 3 4];
f()
I'm compelled to say that I strongly recommend against this type of code as it relies on both globals and calls to eval, both of which should be avoided when possible.
A better method would be to pass in a as an argument to the function
a = [1 2 3];
f = @(x) length(x)
f(a)
a = [1 2 3 4];
f(a)
or, because in this case calling f is identical to calling length, then there's really no reason to use anonymous functions at all.
a = [1 2 3];
length(a)
a = [1 2 3 4];
length(a)
apassed in as an argument?lengthin your function, so why not just uselength? If you need a function handle, usef = @length;.