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!

 채택된 답변

Jan
Jan 2011년 8월 15일

0 개 추천

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

bym
bym 2011년 8월 15일
I don't believe you have any problems with keyboard latency ;)
Jan
Jan 2011년 8월 15일
@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 2011년 8월 16일
Thank you! it worked!!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

bym
bym 2011년 8월 15일

0 개 추천

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

Wei
Wei 2011년 8월 16일
Hi, my fid is very very very long, so I think the previous one is more suitable.
Thank you still!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

Wei
2011년 8월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by