What equivalent MATLAB commands plots PDF of data like 'hist' command plots histogram of data.

조회 수: 1 (최근 30일)
What command does the ploting of the PDF of a data in similar way as 'hist' command plots the histogram? I have a set of data from 1 to 500. My data ranges between -2 and 2. I want to plot the pdf such that the x-axis contains my data (which is -2 to 2 and not 1 to 500 ) while the y-axis is the PDF. When done, this should look similiar to the the result obtained in the 'hist' command.
NOTE: I do not want the result of the 'hist' command and the pdf on the same graph.

채택된 답변

Star Strider
Star Strider 2021년 9월 12일
See if the histfit function does what you want.
.
  댓글 수: 4
ojonugwa adukwu
ojonugwa adukwu 2021년 9월 12일
It does it. Thanks so much.
Meaning there is no single command like hist that plots the PDF of the data directly then.
Star Strider
Star Strider 2021년 9월 12일
As always, my pleasure!
Correct. There is no one command that will estimate the parameters and plot the distribution, at least that does it in the way you want. The handle of histfit has two components, the first being the handle to the bar object and the second being the handle to the line object, so in that sense, it is close. However it will not plot it exactly as you want, with the limits you require, so to get those requires the approach I use in my previous Comment.
.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ive J
Ive J 2021년 9월 12일
편집: Ive J 2021년 9월 12일
Something like this should work:
data = normrnd(10,1,100,1);
pd = fitdist(data, 'Normal');
x_values = 5:0.1:15;
y_values = pdf(pd, x_values);
plot(x_values, y_values, 'LineWidth', 2)

카테고리

Help CenterFile Exchange에서 Exploration and Visualization에 대해 자세히 알아보기

태그

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by