how to format integer numbers to start with filling zeros?

 Accepted Answer

This only makes context in terms of strings, in which case sprintf makes this easy:
>> sprintf('%02d ',1:12)
ans = 01 02 03 04 05 06 07 08 09 10 11 12
And if you want them in a cell array just use strsplit on it, or cellstr.

More Answers (1)

cellstr(num2str((1:12).', '%02d'))
or
arrayfun(@(x) sprintf('%02d', x), 1:12, 'Uniform', 0);

Categories

Asked:

on 15 Dec 2015

Edited:

on 15 Dec 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!