I'm sure there's a way to do this but I don't know what it is.
Suppose I have a vector
v = [1.02 2.03 3.04];
and I want to convert this to a cell array using a format string for each element:
' %.3f'
(3 spaces before the %.3f)
How can I do this? I tried the following approach, but I get an error:
>> f1 = @(x) sprintf(' %.3f',x);
>> cellfun(f1, num2cell(v))
??? Error using ==> cellfun
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
You may wish to use cellfun(..., 'UniformOutput', false)sprintfworks in arrays: i.e. you can usesprintf(' %.3f',v)to print all elements. Maybe, you are creating the cells for sth like this?