I need help converting a large data set with daily temperature values (including NaN values) to monthly values
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 24 Nov. 2019
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.
Antworten (1)
Walter Roberson
am 24 Nov. 2019
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 Kommentare
Walter Roberson
am 25 Nov. 2019
Which MATLAB release are you using? readtable() has been able to read .xls and .xlsx and .csv files since R2013b.
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!