how to extend each element in a cell string array to fixed size?

5 vues (au cours des 30 derniers jours)
Shannon
Shannon le 11 Avr 2020
Commenté : Shannon le 11 Avr 2020
I have a cell string array A={'123', '4567', 67894'}, I want to extend each element to a fixed size, like size of 8, and fill in '0' in front. Like: A={'00000123', '00004567', '00067894'}. Can I get help? Thanks!

Réponse acceptée

David Hill
David Hill le 11 Avr 2020
for k=1:length(A)
A{k}=[repmat('0',1,8-length(A{k})),A{k}];
end

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by