iteration based on a specified number of digits

3 次查看(过去 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.

采纳的回答

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 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by