I noticed anonymous functions in MATLAB can be used without specifying all the needed variables within - however, these don't seem updated at 'runtime' (if I use that term correctly):
a=1;
myfx = @(t) a+t; % a is 1 at this point, the function simply adds 't' to a
a=2;
myfx(1) % a in the base workspace is now 2, yet the function seemingly computes 1+1
ans =
2
Can someone explain what goes on 'under the hood' (i.e. MATLAB-internally) here? It seems unintuitive to me and I imagine this may cause some common pitfalls, that should be taken into consideration.