How can I add leading zeros in a column vector?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
James Condie
el 10 de Jun. de 2016
Comentada: Daniel Pare
el 21 de Jul. de 2020
assuming X is my vertical vector of numbers, I've tried
X_with_zeros=sprintf('%04d\n',X)
It prints out what a want but saves it all combined in a 1x1 char array
I tried this loop:
j=length(length(X));
for i=1:j
X_with_zeros=zeros(j,1);
X_with_zeros(i,1)=X(sprintf('%04d',X(i)),1);
end
It's telling me that my assignment doesn't match the dimensions of the subscript, I've tried different ways. I realize I probably need different rules for a list of strings or char array.
2 comentarios
Azzi Abdelmalek
el 10 de Jun. de 2016
Your question is confusing, you start with leading zeros and end with date problem. Can you make your question clear. Post an example and explain what you want.
James Condie
el 10 de Jun. de 2016
Editada: James Condie
el 10 de Jun. de 2016
Respuesta aceptada
Azzi Abdelmalek
el 10 de Jun. de 2016
v=[0 1 2 3 59 100 101]'
w=arrayfun(@(x) sprintf('%04d',x),v,'un',0)
1 comentario
Daniel Pare
el 21 de Jul. de 2020
Thanks, It works great and fast on table of more than 200k records.
Más respuestas (1)
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!