Open files with for loop with character as title

1 view (last 30 days)
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!

Accepted Answer

Jan
Jan on 15 Aug 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 Comments
Jan
Jan on 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

Sign in to comment.

More Answers (1)

bym
bym on 15 Aug 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 Comment
Wei
Wei on 16 Aug 2011
Hi, my fid is very very very long, so I think the previous one is more suitable.
Thank you still!

Sign in to comment.

Categories

Find more on Entering Commands in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!