How to determine mean values for a table containing nanovalues (where mean values of parts of the rows should be considered individually)
2 views (last 30 days)
I have a table with a lot of rows and a few cols. I want to split the rows for one cols into 10parts in order to analyze the different mean value of each of the 10 parts separately. Unfortunately in some of the 10parts are NaN values. But the following code can't ignore the NaN values, although i am using the nanmean command and thus, for some parts the nanmean value is = NaN^. Anyone know the reason for this happening? Or can someone recommand me a different syntax/code?
Here's my code:
for i=1:10 % for loop to determine 10 mean values %462120 = data collected in 2mins
k(i)=nanmean(Tabk(Tabk>0+(i-1)*462120 & Tabk<i*462120));
s(i)=nanmean(Tabs(Tabs>0+(i-1)*462120 & Tabs<i*462120));
% to calculate the difference
K = transpose(k); %Transponierter Vektor v
S = transpose(s);
D = K-S;
Jyotish Kumar on 22 May 2019
I understand that you are trying to find mean ignoring NaN values. ‘nanmean’ is the right syntax for this purpose and returns mean value ignoring NaN. But it returns NaN if all the elements in the matrix are NaN.
For e.g. nanmean(A) returns 2 for A= [1, NaN, 3] but nanmean(A) returns NaN for A = [NaN, NaN, NaN].
Please refer to this documentation link for more details: