Format numbers in vector with leading zero: 1 -> 01

Is there a way to format a number in Matlab with leading zero?
Suppose I have a number 1, so it would be 01. I need to obtain a number representation of some strings with letters converted into numbers with leading zeros.

Respuestas (1)

the cyclist
the cyclist el 17 de Mayo de 2016
sprintf('%02d',1)

3 comentarios

Stepan Ulyanin
Stepan Ulyanin el 17 de Mayo de 2016
What if I want to have something like: [01 04 08 12] -> [0104 0812], not just print them formatted?
Despite the name, it is not "just printing". It is creating a variable that is the string. You can combine them however you want. For example
s1 = [sprintf('%02d',1),sprintf('%02d',7)]
Stepan Ulyanin
Stepan Ulyanin el 17 de Mayo de 2016
Oh, ok let me check that! Thank you!

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 17 de Mayo de 2016

Comentada:

el 17 de Mayo de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by