editing in string array
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ANKUR KUMAR
el 1 de Nov. de 2017
a={'10','7','5','9','11','12','12','4'}
I want to put 0 at the starting of all those whose length is 1. How can I do this easily?
0 comentarios
Respuesta aceptada
KSSV
el 1 de Nov. de 2017
Editada: KSSV
el 1 de Nov. de 2017
a={'10','7','5','9','11','12','12','4'} ;
L = cellfun(@length,a) ;
idx = L==1 ;
a(idx) = strcat('0',a(idx)) ;
3 comentarios
KSSV
el 1 de Nov. de 2017
cellfun works on the cells.....it is nothing but a for loop on each cell. arrayfun works on rows/ cols of matrices.
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!