reading a csv file with a multiline header and alphanemeric dataset
2 次查看(过去 30 天)
显示 更早的评论
I have a csv file (e.g. filename.csv) with a multiline, irregular header with a fixed length (17 lines). following this, there are columns of data, that I wish to make numeric array. columns may contain empty cells, and non numeric content, which I would want to replace with zeros in my resulting vector. here is the csv file, with a portion of the header:
"Legend"
"M","Missing"
"E","Estimated"
"NA","Not Available"
"**","Partner data that is not subject to review by the National Climate Archives"
"Date/Time","Year","Month","Day","Time","Data Quality","Temp (°C)","Temp Flag","Dew Point Temp (°C)","Dew Point Temp Flag","Rel Hum (%)","Rel Hum Flag","Wind Dir (10s deg)","Wind Dir Flag","Wind Spd (km/h)","Wind Spd Flag","Visibility (km)","Visibility Flag","Stn Press (kPa)","Stn Press Flag","Hmdx","Hmdx Flag","Wind Chill","Wind Chill Flag","Weather"
"2014-04-01 00:00","2014","04","01","00:00","**","2.4","","1.8","","74","","8","","17","","12.9","","101.16","","","","","","NA"
"2014-04-01 01:00","2014","04","01","01:00","**","2.5","","0.9","","78","","7","","21","","16.1","","101.15","","","","","","NA"
"2014-04-01 02:00","2014","04","01","02:00","**","2.1","","0.3","","84","","7","","18","","16.1","","101.09","","","","","","NA"
"2014-04-01 03:00","2014","04","01","03:00","**","2.3","","0.2","","84","","7","","15","","16.1","","101.06","","","","","","NA"
"2014-04-01 04:00","2014","04","01","04:00","**","3.0","","0.9","","76","","7","","13","","16.1","","101.03","","","","","","NA"
"2014-04-01 05:00","2014","04","01","05:00","**","2.8","","0.7","","78","","8","","17","","16.1","","100.96","","","","","","NA"
"2014-04-01 06:00","2014","04","01","06:00","**","2.7","","0.4","","80","","8","","18","","16.1","","100.93","","","","","","NA"
etc.
The data I would like to access is wind direction and wind speed. This should result in a direction vector of:
8
7
7
7
7
8
8
and a speed vector of:
17
21
18
15
13
17
18
I would ideally like two vector, one with direction and the other with speed. If I could obtain another vector with the time (just the hour value) that would be great as well.
Any help is always appreciated!
2 个评论
Image Analyst
2014-4-16
I helped by fixing your formatting above. You could too once you view this : http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
回答(1 个)
Sara
2014-4-16
[~,~,a] = xlsread('file.xlsx','M18:M53');
for i = 1:length(a)
if(~isnumeric(a{i}))
a{i}=0;
elseif(isnan(a{i}))
a{i}=0;
end
end
a = cell2mat(a);
11 个评论
Sara
2014-4-17
I don't get any error running the code for the cvs file you've posted. Just to make sure, is the matlab script in the same folder of the cvs file?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!