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

Patrik Ek
Patrik Ek 2014년 8월 7일
Do they have to be of any numerical type, or is it ok to have them as a char vector?
Sameer
Sameer 2014년 8월 7일
Hi....either double or char
Patrik Ek
Patrik Ek 2014년 8월 7일
Ok I do not think char is the only possiblility, that is why I asked. I would recommend this solution by Andrei Bobrov.

댓글을 달려면 로그인하십시오.

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 8월 7일
편집: Andrei Bobrov 2014년 8월 7일

1 개 추천

arrayfun(@(x)sprintf('%04d',x),1:1000,'un',0);
or
reshape(sprintf('%04d',1:1000),4,[])'

추가 답변 (1개)

Ben11
Ben11 2014년 8월 7일

1 개 추천

A = cell(1,1000);
for k = 1:1000
A{k} = sprintf('%04d',k);
end

카테고리

도움말 센터File Exchange에서 Simulink에 대해 자세히 알아보기

태그

질문:

2014년 8월 7일

댓글:

2014년 8월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by