How to pad all numbers in array ?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
RuiQi
el 11 de Dic. de 2016
Comentada: RuiQi
el 11 de Dic. de 2016
How can I pad a vector of number with zeros ? I am able to do it with a for loop but I was wondering if there is a neater way to do it ?
For example,
a = [1 2 3 4 5];
b = sprintf('%06d',a);
gives me '000001000002000003000004000005'
I would like it to be [000001 000002 .....];
1 comentario
Respuesta aceptada
Stephen23
el 11 de Dic. de 2016
b = sprintf(' %06d',a{:});
^ add this space
Más respuestas (1)
Image Analyst
el 11 de Dic. de 2016
What does that mean? If they're strings, fine -- you can have leading zeros. But if it's a number leading zeros are ignored, so printing or using 000003 will be just the same use using 3. So are you looking for a cell array? If so, see the FAQ: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
3 comentarios
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!