How to convert some numbers to strings with the max length?
Mostrar comentarios más antiguos
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'.
Respuesta aceptada
Más respuestas (2)
the cyclist
el 2 de En. de 2016
An alternative to Image Analyst's (but I prefer his method):
str = num2str(yourInteger,'%02d')
1 comentario
Qiu
el 3 de En. de 2016
Walter Roberson
el 4 de En. de 2016
In the case where you want a bunch of values to all come out the same length, then
cellstr(num2str(TheValues(:)))
You can also toss in an optional format such as
cellstr(num2str(TheValues(:), '%.2f'))
Example:
cellstr(num2str((1:31).'))
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!