MATLAB: Question about the function of callback

callbackguide

hello, I have a question about the writing the function of callback. # how to callback a group of function? For exemple, We use 'callback' like this way: 'callback', @pushbutton_callback. Here pushbutton_callback is a function. In my interface there is many same functions repeated, Can I realize to write the function of callback like @pushbutton_callback(k), and there is the function of callback related. I know writing directly like pushbutton_callback(k) is not correct. I didn't find something similar. What should I do?

Best Answer

Function handles cannot be combined in an array due to the konfusion of the indexing and the input arguments. But you can create a cell of function handles:
C = {@sin, @cos, @tan};
for i = 1:3
feval(C{i}, pi)
% In modern Matlab versions also directly:
% C{i}(pi)
end
Similar works for pushbutton_callback{k}.