I am new to Matlab. I want to display the standard deviation and the mean on a histogram. Can i get Matlab to do this without having to insert the values as text manually?

5 views (last 30 days)
The command legend('text') only seems to accept text inputs, is there a way to make it display the mean and/or standard deviation without me having to enter it?

Answers (1)

José-Luis
José-Luis on 16 Sep 2016
vals = randn(1000,1);
avg = mean(vals);
h = histogram(vals);
legend({sprintf('mean = %3.2f', avg)})

Community Treasure Hunt

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

Start Hunting!