how to take mean of variables from 00 and 12 GMT observations?
Show older comments
% Load the grouping data
lat = ncread(ncfile,'latitude');
lon = ncread(ncfile,'longitude');
expver = ncread(ncfile,'expver');
time = ncread(ncfile,'time');
time = datetime(double(time)*60*60,'ConvertFrom','epochtime','Epoch','1901-01-01');
% convert grouping data to 4x4x2x6961 arrays
[Lon,Lat,Expver,Time] = ndgrid(lon,lat,expver,time);
dataTbl = timetable(Time,Lon,Lat,Expver,d2m,t2m,e,pev,ssr,ssrd,tp,vpd,rh)
% Calculate the mean over latitude x longitude x time
data = groupsummary(dataTbl,["Time","Time"],["hourofday","day"],"mean",4:12)
The above code computes daily average for each day over Lat X Lon and writes
the data of number of rows 3482 for 00 GMT and 3481 for 12 GMT out of total number of observations as 6963. I wish to
calculate the daily average for each day from 00 and 12 GMT also. Therefore,
the dimension of output file becomes (3481,9).
I request you all to please suggest me how to do it in above mentioned code.
Sanchit
5 Comments
Cris LaPierre
on 20 Jul 2023
Edited: Cris LaPierre
on 20 Jul 2023
EDIT: OP deleted their posts.
how to take mean of variables from 00 and 12 GMT observations?
% Load the grouping data
lat = ncread(ncfile,'latitude');
lon = ncread(ncfile,'longitude');
expver = ncread(ncfile,'expver');
time = ncread(ncfile,'time');
time = datetime(double(time)*60*60,'ConvertFrom','epochtime','Epoch','1901-01-01');
% convert grouping data to 4x4x2x6961 arrays
[Lon,Lat,Expver,Time] = ndgrid(lon,lat,expver,time);
dataTbl = timetable(Time,Lon,Lat,Expver,d2m,t2m,e,pev,ssr,ssrd,tp,vpd,rh)
% Calculate the mean over latitude x longitude x time
data = groupsummary(dataTbl,["Time","Time"],["hourofday","day"],"mean",4:12)
The above code computes daily average for each day over Lat X Lon and writes
the data of number of rows 3482 for 00 GMT and 3481 for 12 GMT out of total number of observations as 6963. I wish to
calculate the daily average for each day from 00 and 12 GMT also. Therefore,
the dimension of output file becomes (3481,9).
I request you all to please suggest me how to do it in above mentioned code.
Sanchit
_______________________________________________________________________________
Response
Why start a duplicate question, especially since the code you are posting here is from my answer there?
Original question can be found here: https://www.mathworks.com/matlabcentral/answers/1997658-how-do-i-compute-mean-values-of-nine-variables-over-lat-x-lon-x-time
________________________________________________________________________________
OP
Dear Cris LaPierre,
This is not a duplicate question but it is partly unanswered question. I requested in my first post to get daily mean of all the variables each day for 00 and 12 GMT observations also. But this code does not do that. That is why I have again posted this code to get my answer. I request you to please suggest me how to get daily mean of nine variables each day from 00 and 12 GMT also using this code. I would be grateful to you for your kind help.
Sanchit
Cris LaPierre
on 20 Jul 2023
Edited: Cris LaPierre
on 20 Jul 2023
It does do that. I've commented as much in the original question.
______________________________________________________________________________
OP
But I am getting the 00 and 12 GMT data seperately written in my output file. The dimension of output file should be (3481,11) not (6963,11). Please I request you to get the mean of 00 and 12 GMT data also.
Sanchit
Devendra
on 20 Jul 2023
Hi Cris, Is it possible to get the mean of 00 and 12GMT observations also for nine variables in addition to mean over Lat x Lon boxes using the above code?
I am curious to know. Would greatly appreciate your reply. Devendra Chahar
Cris LaPierre
on 20 Jul 2023
Rena Berman
on 31 Jul 2023
(Answers Dev) Restored edit
Answers (1)
Walter Roberson
on 20 Jul 2023
0 votes
2 Comments
Sanchit
on 20 Jul 2023
Walter Roberson
on 20 Jul 2023
retime(dataTabl(:,4:12), 'hourly', 'mean')
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!