In any case, I would have found a better way to implement the evaluation of each component of the turbulent kinetic energy. As a matter of fact, since the TKE of each component of the velocity depends only by its variance, it would be sufficient to evaluate both component of TKE as follows:
-----------------------------------------------------------
TKE_u=0.5*var(umittelselected,0,3,'omitnan');
TKE_v=0.5*var(vmittelselected,0,3,'omitnan');
-----------------------------------------------------------
I've put 0 as weight in the variance function (i.e. normalization by N-1 with N number of observation) since you are evaluating the standard deviation in the same way. In my opinion, this strategy is better for two reasons.
The first is that this fixes a problem related to the fact that, in the way you have implemented the TKE calculation, you are normalizing by N the variance, as you can see if you run the lines below as test:
-----------------------------------------------------------
A=1:10;
A_prime=A-mean(A);
A_prime_squared_mean=mean(A_prime.^2);
var1=var(A,0); %normalized by N-1
var2=var(A,1); %normalized by N
check=[A_prime_squared_mean==var1 A_prime_squared_mean==var2];
-----------------------------------------------------------
You will see that check=[0 1], meaning that in the way you are evaluating the TKE, you are normalizing by N the variance, but this is in contrast with what you did for the evaluation of the standard deviation some lines below (lines 219-220 in the 'temporal_operation_Callback.m' function), where you have normalized by N-1 (weight 0 in the std function).
The second advantage of following my suggested method is that you avoid a creation of two (unnecessary) 3D matrix like u_prime and v_prime, saving RAM memory (this may be crucial if you are analyzing thousands of images) and computational cost.
Therefore, I would suggest to change lines 189-205 in the 'temporal_operation_Callback.m' function with the lines I have proposed. Please do not hesitate to contact me should you have questions or doubts.