Problem with mean function
古いコメントを表示
Okey, so I have the two nx2 vectors "day" and "comp_r".
I want to calculate the mean for a certain day, say day 8.
condition = day(:,1) == 8;
avg_day_8 = mean( comp_r( condition, 1) );
The problem is that I get that the mean equals NaN, and I am sure that's a wrong answer.
So what am I doing wrong?
回答 (1 件)
James Tursa
2017 年 2 月 27 日
編集済み: James Tursa
2017 年 2 月 27 日
What does this show:
sum(condition)
If sum(condition) is 0, then you will get a NaN result in the mean calculation. E.g.,
>> x = reshape(1:6,3,2)
x =
1 4
2 5
3 6
>> condition = x(:,1) < 1
condition =
0
0
0
>> mean(x(condition,1))
ans =
NaN
2 件のコメント
Hampus
2017 年 3 月 1 日
James Tursa
2017 年 3 月 1 日
What does this show:
any(isnan(comp_r( condition, 1)))
カテゴリ
ヘルプ センター および File Exchange で MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!