Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab: mean value in 4-d matrix

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.

like image 599
Kuo-Hsien Chang Avatar asked Nov 30 '22 20:11

Kuo-Hsien Chang


1 Answers

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
like image 52
Prashant Kumar Avatar answered Dec 04 '22 11:12

Prashant Kumar