How can I print the mean and standard deviation in the histogram plot?
50 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Navid
am 8 Nov. 2023
Kommentiert: Navid
am 15 Nov. 2023
Hi there
Dear all, I used the syntax below to plot the histogram:
h = histfit(x)
A probability distribution is also obtained from:
pd = fitdist(x,'Normal')
How can I automatically display the mean (mu) and standard deviation (sigma) in the histogram plot?
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 9 Nov. 2023
I don't know if you can do it "automatically" but you can manually use title or text to display text on the chart:
x = randn(1000, 1);
h = histfit(x)
% A probability distribution is also obtained from:
pd = fitdist(x,'Normal')
grid on;
% Display the mean and std dev.
caption = sprintf('Mean = %f, StDev = %f', pd.mu, pd.sigma);
title(caption)
5 Kommentare
Paul Barrette
am 15 Nov. 2023
I do not yet have that tool box (the quote I got for this license is about USD 1000), so am unable to comment on that function.
Weitere Antworten (2)
Steven Lord
am 15 Nov. 2023
The other posters have interpreted "print" in the subject of your Answers post as displaying the numeric value. Another potential interpretation of that (and the word you used later in your question, "display") is to draw lines representing the mean and standard deviations. If you're interested in that visualization of the statistical quantities, use the xline function. I've slightly adapted the "Create Multiple Lines with Labels" example from that page for the example below.
x = randn(1, 1e5); % Sample data
h = histogram(x);
m = mean(x);
s = std(x);
xline([m, m-s, m+s], ":", ["\mu", "\mu- \sigma", "\mu+ \sigma"], ...
"Color", "r", "FontWeight", "bold")
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!