Hello,
I have 2 histograms with 5000 and 50 random samples. (Mu=5 and sd=7) I want to add their pdf and cdf curve on my histograms.
Can you help me, please?
xNormal = random('Normal',5,7,1,5000);
h = histogram(xNormal,'Normalization','pdf')
hold on
yNormal = random('Normal',5,7,1,50);
hold on
h = histogram(yNormal,'Normalization','pdf');
hold on
xlabel('Class Intervals');
ylabel('Frequency');

1 件のコメント

Rik
Rik 2020 年 3 月 10 日
Please don't double-post your question.

サインインしてコメントする。

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 3 月 10 日
編集済み: Ameer Hamza 2020 年 3 月 10 日

1 投票

You are already plotting the pdf of these distributions. Do you want to draw cdf on the same graph? If so, just pass the option 'Normalization','pdf' to the histogram function. For example,
xNormal = random('Normal',5,7,1,5000);
yNormal = random('Normal',5,7,1,50);
estimated_dist_x = fitdist(xNormal', 'Normal');
xRange = linspace(min(xNormal), max(xNormal));
xPdf = pdf(estimated_dist_x, xRange);
xCdf = cdf(estimated_dist_x, xRange);
estimated_dist_y = fitdist(xNormal', 'Normal');
yRange = linspace(min(yNormal), max(yNormal));
yPdf = pdf(estimated_dist_y, yRange);
yCdf = cdf(estimated_dist_y, yRange);
fig1 = figure();
hold on;
xlabel('Class Intervals');
histogram(xNormal,'Normalization','pdf');
plot(xRange, xPdf, 'LineWidth', 2);
ylabel('pdf');
yyaxis right
plot(xRange, xCdf, 'LineWidth', 2);
ylabel('cdf');
fig2 = figure();
hold on;
xlabel('Class Intervals');
histogram(yNormal,'Normalization','pdf');
plot(yRange, yPdf, 'LineWidth', 2);
ylabel('pdf');
yyaxis right
plot(yRange, yCdf, 'LineWidth', 2);
ylabel('cdf');

5 件のコメント

N/A
N/A 2020 年 3 月 10 日
But I have 2 different histograms and I want pdf and cdf as a curve on my histagrams.
This code provide cdf as columns.
I need 2 pdf and 2 cdf on my 2 histograms. (different pdf and cdf for each histogram)
Ameer Hamza
Ameer Hamza 2020 年 3 月 10 日
If you want to draw curves, then have a look at the updated code in my answer.
N/A
N/A 2020 年 3 月 10 日
It gives me pdf and cdf as histogram. I need curves. Here my output in the attachment.
Ameer Hamza
Ameer Hamza 2020 年 3 月 10 日
You ran the older code again. The updated code is changed.
N/A
N/A 2020 年 3 月 10 日
oh, thank you :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Interpolation についてさらに検索

質問済み:

N/A
2020 年 3 月 10 日

コメント済み:

N/A
2020 年 3 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by