iteration based on a specified number of digits
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!