I need help converting a large data set with daily temperature values (including NaN values) to monthly values
3 次查看(过去 30 天)
显示 更早的评论
Using the daily temperature data which I am obtaining from a canadian website with temperature data from 1977-2016, how can I extract the mean monthly temperature of each month from 1977-2016, the extreme minimum monthly temperature( so the coldest temperature of the month for every month between 1977-2016) and the same for the extreme max temperature (so the hottest temperature of the month for each month in the range of 1977-2016). Note there are some data missing which is replaced with NaN values. So the nanmean,nanmin,nanmax functions will need to be used I believe. Here is a screenshot of a portion of the the data I am using. So basically my main problem is converting the daily temperature data into monthly data based on what Im given. If anyone can help and provide simple and clear example(s) it would be greatly appreciated. Thanks.
%col1=years
% col2=months
% col3=days of the week
% col4=max daily temp
% col5=blank
% col6=min daily temp
% col7=blank
% col8=mean daily temp
2 个评论
Walter Roberson
2019-11-24
Often the easiest way is to readtable() the file, use the appropriate columns to create datetime() values, then convert the table to a timetable() object, after which you can use retime() to get the information you are looking for.
回答(1 个)
Walter Roberson
2019-11-24
T = readtable('YourFile.xlsx', 'readvariablenames', false); %true if there is a header
dt = datetime(T{:,1}, T{:,2}, T{:,3});
TT = table2timetable(T, 'rowtimes', dt);
month_mean = retime(TT(:,8), 'monthly', 'mean');
month_min = retime(TT(:,6), 'monthly', 'min');
month_max = retime(TT(:,4), 'monthly', 'max');
summary = [month_mean, month_min, month_max];
2 个评论
Walter Roberson
2019-11-25
Which MATLAB release are you using? readtable() has been able to read .xls and .xlsx and .csv files since R2013b.
另请参阅
类别
在 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!