Very simple logical question

5 vues (au cours des 30 derniers jours)
Sameer
Sameer le 7 Août 2014
Commenté : Patrik Ek le 7 Août 2014
Hello all
I want to generate the set of numbers such that each number is having the same number of digits.
Something like this: 0001,0002,0003,.....0010,0011,0012,.....0100,0101,0102.....,0998,0999,1000
can anyone please help me with this?
Regards
  3 commentaires
Sameer
Sameer le 7 Août 2014
Hi....either double or char
Patrik Ek
Patrik Ek le 7 Août 2014
Ok I do not think char is the only possiblility, that is why I asked. I would recommend this solution by Andrei Bobrov.

Connectez-vous pour commenter.

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 7 Août 2014
Modifié(e) : Andrei Bobrov le 7 Août 2014
arrayfun(@(x)sprintf('%04d',x),1:1000,'un',0);
or
reshape(sprintf('%04d',1:1000),4,[])'

Plus de réponses (1)

Ben11
Ben11 le 7 Août 2014
A = cell(1,1000);
for k = 1:1000
A{k} = sprintf('%04d',k);
end

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