function varargout = celldeal(input_cell_array) %CELLDEAL like DEAL but takes a cell array: a bit like @(x) deal(x{:}) % % This one-liner is like Matlab's standard deal, but takes a cell array of % inputs rather than an argument list. % I find this useful for constructing anonymous functions that need to % return multiple arguments. Note that Matlab (unlike Octave) won't allow % expressions like: % new_fn = @(x) deal(fn_returning_cell_array(x){:}); % So I do: % new_fn = @(x) celldeal(fn_returning_cell_array(x)); % % Unlike deal, this function doesn't crash if fewer output arguments than % available are requested. % % Unlike deal there is no facility for copying a single input into multiple % outputs. % % Example usage: % >> [a, b, c] = celldeal({1, [3,5], 7, 9}) % a = % 1 % b = % 3 5 % c = % 7 % Iain Murray, November 2007 % When called without return values, nargout==0, we return 1 output. varargout = input_cell_array(1:max(1,nargout));