Open files with for loop with character as title

Hi,
I have a bunch of files to open and they are classed by month. Usually I would use a for loop and num2str to convert numbered month to string to read them, however the months are written in characters (AUGUST, MAY, etc)
Anyone knows how to solve this issue without changing the name of the files one by one?
Thanks in advance!

 Réponse acceptée

Jan
Jan le 15 Août 2011
MonthName = {'January', 'February', 'March', 'April', 'May', 'June', ...
'Jule', 'August', 'September', 'October', 'November', 'December'};
for year = 2000:2010
for month = 1:12
disp(sprintf('%04d%s', year, MonthName{month}))
end
end

3 commentaires

bym
bym le 15 Août 2011
I don't believe you have any problems with keyboard latency ;)
Jan
Jan le 15 Août 2011
@proecsm: I gave up after sending so many mails and after so many discussions here in the last 6 month. I've solved the problems of the hilarious inefficient screen updates by buying a more powerful computer and Windows 7. Now the latency disappeared, but I'm quite disappointed, because I know that the auto-preview still wastes a lot of energy, although I do not feel it anymore.
See: http://www.mathworks.com/matlabcentral/answers/5560-do-you-suffer-from-keyboard-latency-in-this-forum
Wei
Wei le 16 Août 2011
Thank you! it worked!!

Connectez-vous pour commenter.

Plus de réponses (1)

bym
bym le 15 Août 2011
something like this?
fileInfo = dir('*.csv'); % csv files in directory
numFile = length(fileInfo);
rawData = cell(1,numFile);
for i = 1:numFile
fid = fopen(fileInfo(i).name);
rawData{i} = textscan(fid,'%*s%*s%*s%s%*s%f','delimiter',',');
fclose(fid);
end

1 commentaire

Wei
Wei le 16 Août 2011
Hi, my fid is very very very long, so I think the previous one is more suitable.
Thank you still!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by