john - is the above code nested within another function so that the function1 has access to the encoder variable which (presumably) has been initialized in that other/parent function? Note that there is no output parameter for a timer function callback, and the default parameters (of which there are generally two) correspond to the handle of the timer object and some event data (if it exists). So the above might not work as you intend. An example might be
k = 1;
T = ;
T(k) = randi(256,1,1);
k = k + 1;
Note how we must define the nested variables that the function1 callback will access before we assign the timer callback. And instead of returning an output parameter from the callback - which you cannot do - we store the result in an array (or you could do something with that value (i.e. update a plot) from within the callback.