for loop does not work to iterate through 600+ csv files
1 次查看(过去 30 天)
显示 更早的评论
I am trying to write code to iterate over a series of csv files, each that represents a county in the United States, that are saved with the countynumber.csv (ex: 1003.csv).
I have 631 counties ranging from 1003 to 55139 (not each number in between though), and I want to calculate some aspects (maximum values and their locations, as shown in my code) and display the results for each of the 631 counties in a table, which is the last line of my code.
How can I iterate through the 631 counties and display their results in one 631x6 table? Why is my for loop not working?
Code so far:
whichBin = {2012:2013};
binType = 'annual';
binList = {2012:2013};
geoRegion = 'FIPS';
whichYears = [2012:2013];
whichDay = 'wkend';
randStr = 'gbqo';
for geoCode=1003:55139
csvData = ['tweetograms/tweetograms_' binType '_' geoRegion '_2012_2013_' randStr '/' binType '/' whichDay '/' num2str(geoCode) '.csv'];
if ~exist(csvData,'file'),continue,end
tweetogramData = csvread(csvData);
tweetogramSmooth = smooth(tweetogramData)
[lunchpk, loc1] = max(tweetogramSmooth(44:60));
[dinnerpk, loc2] = max(tweetogramSmooth(68:92));
lunchloc = loc1 + 43;
dinnerloc = loc2 + 67;
outTable(geoCode,:) = table(geoCode, whichDay, lunchloc, lunchpk, dinnerloc, dinnerpk);
end
6 个评论
Stephen23
2018-7-17
@Mili Shah: you should follow Rik Wisselink's very good advice. Also read this:
It would be much simpler if you used dir.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!