Having a function handle sometimes means that you want to be flexible regarding the number of input arguments.
having a function handle fhandle=@plot
means that you can call fhandle() but is you want to pass a variable number of arguments to fhandle that resides in a cell array, cparameters, containing e.g.: cparameters={[1:10],’resize’,’no’} you can do:
fhandle(cparameters{:}) which will result in e.g. plot([1:10],’resize’,’no’)
In the case where you want additional stuff to happen – e.g. add title to the plot you can do:
fhandle=@(data,titlestr,varargin) plot(data,varargin{:}) && title(titlestr)
cparameters={1:10,'test title','LineWidth',5}
fhandle(cparameters{:})
Will produce
plot(1:10,’LineWidth’,5) && title(titlestr)
Tags: cellarray, function handle, matlab, varargin