# how can I take mean of fourth dimension of daily data?

4 views (last 30 days)
Aarti Soni on 8 Sep 2022
Edited: Cris LaPierre on 3 Oct 2022
I have hourly data and I want to convert it into monthly mean.
I have daily data for 20 years (.nc files) and the structure of the daily data is 180 X 360 X 4 X 8, where 8 is hourly data. I want to take mean of 8hours that will represent observation of the day and then finally want to convert it into monthly.
Any kind of help would be appreciated.
Thanks
Cris LaPierre on 3 Oct 2022
Edited: Cris LaPierre on 3 Oct 2022
SM is an array of data type single. Singles are 32 bit numbers. So saving 75x100x4x8 = 240,000 singles at 4 bytes per number should yield a mat file size of approximately 960 KB, well under the 5 MB upload limit. Including Times and lev only adds 0.1 KB.

Cris LaPierre on 3 Oct 2022
Edited: Cris LaPierre on 3 Oct 2022
I see your times are recorded as decimal days:
Times =
0
0.1250
0.2500
0.3750
0.5000
0.6250
0.7500
0.8750
Note that you have measurements taken at 4 levels each time (your 3rd dimension)
lev =
1
2
3
4
Therefore, the most logical way to me to compute a daily average is to compute the mean of the 8 SM values at each lon/lat pair and each level. This means the result will by lon x lat x lev (e.g. 50x50x4)
This cam be accomplished by useing the mean function and specifiying which dimension to take the mean in. Here, that is the 4th dimension, or time.
dayAvg = mean(SM,4);
Your file only contains information for a single day, so you would need to take the average of each file and then combine the results to compute a monthly average. Again, you will have a daily average for each leavel (4 values per lon/lat pair).

### Categories

Find more on Variables 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!

Translated by