How to determine mean values for a table containing nanovalues (where mean values of parts of the rows should be considered individually)
2 次查看(过去 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;
0 个评论
回答(1 个)
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:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!