Matlab fprintf function returning cell array of strings
Alec Jacobson
June 20, 2011
I always forget how to fprintf the output of a function return a cell array. For example:
fprintf('**%s\n',depfun('magic','-quiet'));
Produces the error:
??? Error using ==> fprintf
Function is not defined for 'cell' inputs.
The solution for passing each string in the cell array to fprintf is simple if you can first save the output to a variable:
A = depfun('magic','-quiet');
fprintf('**%s\n',A{:});
Correctly produces
**/Applications/MATLAB_R2010b.app/toolbox/matlab/elmat/magic.m
**/Applications/MATLAB_R2010b.app/toolbox/matlab/datatypes/@opaque/char.m
**/Applications/MATLAB_R2010b.app/toolbox/matlab/datatypes/@opaque/double.m
**/Applications/MATLAB_R2010b.app/toolbox/matlab/datatypes/@opaque/toChar.m
**/Applications/MATLAB_R2010b.app/toolbox/matlab/elmat/meshgrid.m
**/Applications/MATLAB_R2010b.app/toolbox/matlab/ops/@opaque/eq.m
**/Applications/MATLAB_R2010b.app/toolbox/matlab/strfun/@opaque/findstr.m
**/Applications/MATLAB_R2010b.app/toolbox/matlab/strfun/@opaque/private/fromOpaque.m