Hello everyone. I was wondering how can I add vertical lines of standard deviation, mean, median , among other statistical results to a plot made with the function ‘ksdensity’ ? thank you.

 採用された回答

Cris LaPierre
Cris LaPierre 2021 年 5 月 31 日

0 投票

Use xline.
% create a distribution with known mean, std
pd = makedist('Normal','mu',2.5,'sigma',3.1);
x = random(pd,100,1);
[f,xi] = ksdensity(x);
figure
plot(xi,f);
% Add vertical lines
xline(2.5)
xline(2.5+[-3.1,3.1])

3 件のコメント

Fercho_Sala
Fercho_Sala 2021 年 5 月 31 日
@Cris LaPierre in your expample you know the 'mean', however how can I do it in the case we don't know this value and the dataset has several NaN ?
Cris LaPierre
Cris LaPierre 2021 年 5 月 31 日
Calculate it.
mn = mean(x,'omitnan')
Fercho_Sala
Fercho_Sala 2021 年 6 月 1 日
@Cris LaPierre how can I display the value of that 'mean' in the left, right side of the line? the x axis? , thanks.

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

その他の回答 (0 件)

製品

リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by