iteration based on a specified number of digits

조회 수: 1 (최근 30일)
Meh
Meh 2013년 2월 22일
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.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 22일
편집: Azzi Abdelmalek 2013년 2월 22일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by