There is a cool undocumented function called sprintfc
that prints to cell arrays:
An = 1:0.0001:1.1;
As = sprintfc('%g',An)
Example:
>> A = sprintfc('%g',0:0.2:1)
A =
'0' '0.2' '0.4' '0.6' '0.8' '1'
>> which sprintfc
built-in (undocumented)
sprintfc
was recently highlighted on undocumentedmatlab.com. Yet another great find by Yair Altman. Some other possibilities follow.
For numerical values, use num2cell
:
A = num2cell(An)
For string representations:
A = strsplit(num2str(An))
You could also use cellfun
:
A = cellfun(@num2str,num2cell(An),'uni',0)
Or just arrayfun
, which is actually simpler:
A = arrayfun(@num2str,An,'uni',false)