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!

 Akzeptierte Antwort

Jan
Jan am 15 Aug. 2011

0 Stimmen

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 Kommentare

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

bym
bym am 15 Aug. 2011

0 Stimmen

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 Kommentar

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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Hilfe-Center und File Exchange

Gefragt:

Wei
am 15 Aug. 2011

Community Treasure Hunt

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

Start Hunting!

Translated by