필터 지우기
필터 지우기

How to determine mean values for a table containing nanovalues (where mean values of parts of the rows should be considered individually)

조회 수: 1 (최근 30일)
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));
i=i+1;
end
% to calculate the difference
K = transpose(k); %Transponierter Vektor v
S = transpose(s);
D = K-S;

답변 (1개)

Jyotish Kumar
Jyotish Kumar 2019년 5월 22일
Hi,
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:

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by