Tuesday, June 23, 2009

Q: Matlab - How do you get numbers to format with zeros?

i.e. I have a bunch of file names that look like 0001, 0002 .... 0237 and so on. To create strings in order to load the files, I have to do something like

Filenumber = 1:237;
for x = Filenumber
Name = num2str(x)
eval('load(' Name ')')
end

but that doesn't work because I need the Filenumber to be '0001' not just '1'. :(

A. Use num2str(20,'%04i')

No comments: