Borrar filtros
Borrar filtros

iteration based on a specified number of digits

3 visualizaciones (últimos 30 días)
Meh
Meh el 22 de Feb. de 2013
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.

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 22 de Feb. de 2013
Editada: Azzi Abdelmalek el 22 de Feb. de 2013
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

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by