How to add: min, max, mean, median, st dev values to histogram legend
조회 수: 14 (최근 30일)
이전 댓글 표시
I would like to add information about min, max, mean, median, and st dev to the histogram. I tried to do this using the following script:
% Import data
A = importdata('C:\my_data.tif');
% Generate histogram
histogram(A,'BinLimits',[0,1000]);
% Calculate the min, max, mean, median, and standard deviation
min=min(A);
max=max(A);
mn=mean(A);
md=median(A);
stdv=std(A);
% Create the labels
minlabel=sprintf('Min -- %3.2d', min);
maxlabel=sprintf('Max -- %3.2d', max);
mnlabel=sprintf('Mean -- %3.2d', mn);
mdlabel=sprintf('Median -- %3.2d', md);
stdlabel=sprintf('Std Deviation -- %3.2d', stdv);
% Create the textbox
h=annotation('textbox',[0.58 0.75 0.1 0.1]);
set(h,'String',{minlabel, maxlabel,mnlabel, mdlabel, stdlabel});
However, every time when I run the script the last line of the script crushed in Matlab (see attached message). Does anyone know how to solve the error? Or is there another way to add min, max info to the histogram? Thanks in advance for the answer.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/151854/image.png)
댓글 수: 0
답변 (2개)
Sean de Wolski
2015년 7월 6일
I'd contact tech support if the crash is reproducible.
A minimal working example works for me:
histogram(rand(100,1))
annotation('textbox','String',{'hello', 'world'})
댓글 수: 0
Karolina
2015년 7월 6일
편집: Karolina
2015년 7월 6일
댓글 수: 4
Sean de Wolski
2015년 7월 7일
Contact tech support! It could quite possible by a simple graphics driver update or something specific to your machine that they can help with!
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!