Effacer les filtres
Effacer les filtres

iteration based on a specified number of digits

3 vues (au cours des 30 derniers jours)
Meh
Meh le 22 Fév 2013
I want to have a string which goes like 0001,0002, 0003...,0009, 0010,0011,...,0099,0100,0101,...0150. In short I want to keep the number of digits constant how can I do this in matlab. I can write for each separate number of digits like:
for i=1:9
a=strcat('000',num2str(i))
end
then I continue for 10 to 99; and then for the remaining 100 to 150. But I want to know if there is a simpler way of doing this.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 22 Fév 2013
Modifié(e) : Azzi Abdelmalek le 22 Fév 2013
for k=1:150
s=fix(log10(k)) % or s=numel(num2str(k))-1
a=sprintf('000%d',k)
a(1:s)=[]
out{k}=a;
end
out

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by