MATLAB: Add blank spaces in cell array

cellsformatMATLABstrings

I have the following array
ar=
0 1 0 0 0 0 0 0 0 0
0 0 0 3 0 0 0 0 0 0
0 0 0 0 0 0 2 0 0 0
0 0 0 0 0 0 0 0 3 0
4 0 0 0 0 0 0 0 0 0
And I would like to create a 5×1 cell array C like this one:
C =
5×1 cell array
{' 0 1 0 0 0 0 0 0 0 0'}
{' 0 0 0 3 0 0 0 0 0 0'}
{' 0 0 0 0 0 0 2 0 0 0'}
{' 0 0 0 0 0 0 0 0 3 0'}
{' 4 0 0 0 0 0 0 0 0 0'}
That is with 10 blank spaces at the beginning of each row. I tried this:
fmt=repmat(' % 11.1i',1,10);
fmt=[' ' fmt4(2:end) '\n'];
rew=num2str(ar,fmt4)
tes=num2cell(ar)
C = cellfun(@cell2mat,num2cell(tes,2),'un',0)
And I get this:
C =
5×1 cell array
{'0 1 0 0 0 0 0 0 0 0'}
{'0 0 0 3 0 0 0 0 0 0'}
{'0 0 0 0 0 0 2 0 0 0'}
{'0 0 0 0 0 0 0 0 3 0'}
{'4 0 0 0 0 0 0 0 0 0'}
Is there a way to add the blank spaces in cell array C?

Best Answer

ar = [0,1,0,0,0,0,0,0,0,0; ...
0,0,0,3,0,0,0,0,0,0; ...
0,0,0,0,0,0,2,0,0,0; ...
0,0,0,0,0,0,0,0,3,0; ...
4,0,0,0,0,0,0,0,0,0];
fmt = repmat('%11d', 1, size(ar,2));
% Either:
C = sprintfc(fmt, ar); % Unfortunately not documented
% Or:
D = compose(fmt, ar) % Working since R2016b