I have a 4-d matrix (time, one_variable, Y_location, X_location) in Matlab.
Here is the 4-d matrix looks like:
>> size (npp_data_pft1)
ans =
100 1 289 570
100 means 100 timesteps; 1 means only 1 variable here; 289 and 570 are the y and x gridded cell indices.
How to get a mean value in a specific region?
For example, I like to get a mean value in timestep 1 within a region at 33 < Y_location < 47 and 112 < X_location < 176.
One way to do it is to extract your region and then take the mean.
A = npp_data_pft1(1, 1, 33:47, 112:176);
mean(A(:)) % returns scalar value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With