MATLAB中的直方图拟合和内核密度图

时间:2017-08-05 09:25:41

标签: matlab image-processing machine-learning signal-processing

我想绘制直方图拟合和核密度曲线在一个图中意味着在图中ks密度曲线和histfit在一帧中。

有人可以帮我怎么做。

我只是提供一个示例代码,我想做什么。

非常感谢。

  x = rand([1 50])
  figure(1)
  histfit(x)
  hold on 
  [f,xi] = ksdensity(x);
  hold off
  figure
  plot(xi,f);

1 个答案:

答案 0 :(得分:1)

The function calls for plotting are incorrect. Essentially, hold on asks MATLAB to plot everything thereafter, overlapping the previous figure. hold off disables this and overwrites the previous figure. Hence, run the code like this:

x = rand([1 50])
figure(1)
histfit(x)
hold on 
[f,xi] = ksdensity(x);
plot(xi,f);
hold off