1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MATLABの histogram で 'Normalization', 'Probability' は nan まで計算に入ってしまう

Posted at

N数が違う histogram を重ねる時,y軸を 'Prpbability' にすると思うが,NaN まで計算に入れているみたいなので注意.
↓のような事が簡単に起こる (二つのヒストグラムの面積の合計同じにならない).

x = randn(1,1000);
nanx = x;
nanx(:) = nan;
y = [x nanx];

figure;
histogram(y, -5:.5:5, 'Normalization', 'probability', 'DisplayStyle', 'stair'); hold on;
histogram(x, -5:.5:5, 'Normalization', 'probability', 'DisplayStyle', 'stair');

untitled.png

解決策

histogram(y(~isnan(y)), -5:.5:5, 'Normalization', 'probability', 'DisplayStyle', 'stair'); hold on;

みたいにする.めんどくさい…

MATLAB2017a で確認.

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?