Take the following example:
clear all
depth = [0,2,4,7,10,13,16,19,22,25,30,35];%depth below surface
temp = 0 + 29.*rand(365,12);
thermD = 0 + 36.*rand(365,1);
temp refers to the temperature profile of a water column, where each column refers to a different depth where this depth is given by ‘depth’.
thermD is a variable which describes the region of greatest temperature difference in the water column.
I’m trying to create a variable which shows the mean of the temperature above the region of greatest density difference denoted by thermD.
So, for example, if the value in thermD is 12 (i.e. the region of greatest temperature difference is at 12 meters below the surface) then I would need to calculate the mean temperature for the first 5 columns in ‘temp’ as column 1:5 (as denoted in depth) represent the temperature below between the surface and this depth.
Any advice would be much appreciated.
I believe this will do what you need, it may not be vectorized, but I think it’s fairly clear:
Hope this is helpful.