MATLAB: How to format integer numbers to start with filling zeros

digitformatintegernumberprintfstringzero

I would like to transform n = 1:12 to '01','02',…,'11','12'

Best 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.