MATLAB: How to convert some numbers to strings with the max length

convert

for example, I want to convert 1 to 32 to strings length 2, if shorter, '0's are added to the front of the strings. 1 -> '01', 2 -> '02', …, 32 -> '32'.

Best Answer

str = sprintf('%2.2d', yourInteger)