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!

 Respuesta aceptada

Jan
Jan el 15 de Ag. de 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 comentarios

bym
bym el 15 de Ag. de 2011
I don't believe you have any problems with keyboard latency ;)
Jan
Jan el 15 de Ag. de 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 el 16 de Ag. de 2011
Thank you! it worked!!

Iniciar sesión para comentar.

Más respuestas (1)

bym
bym el 15 de Ag. de 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 comentario

Wei
Wei el 16 de Ag. de 2011
Hi, my fid is very very very long, so I think the previous one is more suitable.
Thank you still!

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

Wei
el 15 de Ag. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by