Histograms - Mean calculation - Comparing more pdf

조회 수: 2 (최근 30일)
Gianluca Borgna
Gianluca Borgna 2019년 3월 25일
댓글: Gianluca Borgna 2019년 3월 26일
Hi everyone!
I have 3 questions!
1) I would like to do an histogram in which i have numbers in ordinates and names in absissae. I have no idea how to do it in Matlab.
2) I need a graph in which i plot how the mean stablizes itself as a function of the sampling.
I have 100 values and i should take the mean progressively.
For example [1 2 3 4].
I need a vector that take the mean [mean(1), mean (1+2), mean (1 + 2+ 3), mean (1+2+3+4)]. How to do that?
3) I'm comparing 2 probability density functions and i would like to know if it is possible to use different colors in the zone in common between the 2 histograms.
What Matlab does it is just to blaken the zone. I would like to know if it is possible to choose different colors.
Thanks in advance!

채택된 답변

Rik
Rik 2019년 3월 25일
For your first question: you can either use a categorical array, or set the xticks and xticklabels.
You can calculate the progressive mean with the help of cumsum:
data=rand(100,1);
%make sure to only input vectors
prog_mean=cumsum(data)./cumsum(ones(size(data)));
As for your third question, please post the code you use. It is often easier to adapt code that almost does what it needs to do, then guess your data structure and appropriate code.
  댓글 수: 5
Rik
Rik 2019년 3월 26일
I prefer setting the DisplayName property in my calls to plot and then only turning the legend on. You can also do it differently, please read the doc for the legend function. Matlab documentation is actually pretty good. You will find several examples there, including the allowed forms of syntax.
The code below should give you an idea as well. Also: try using arrays of handles, instead of numbered variables. Numbered variables are generally a bad idea.
f=[];%clear f in case it already exists to prevent unexpected outcomes
figure; histogram(af_Caramagna,CaramagnaEdges,'Normalization','pdf','FaceColor',[0.3010 0.7450 0.9330]);
hold on; f(1)=plot(CaramagnaEdges, Caramagna_distr, 'linewidth',2, 'color','b'); grid minor;
hold on;
histogram(af_CaramagnaDeg1,CaramagnaEdges,'Normalization','pdf','FaceColor','r');
f(2)=plot(CaramagnaEdges, CaramagnaDeg1_distr, 'linewidth',2, 'color','r');
legend(f,...
['\mu = ' num2str(round(Caramagna_mean,2)) ' \sigma = ' num2str(round(Caramagna_std,2)) ' CoV = ' num2str(round(Caramagna_cov,2))], ...
['\mu = ' num2str(round(CaramagnaDeg1_mean,2)) ' \sigma = ' num2str(round(CaramagnaDeg1_std,2)) ' CoV = ' num2str(round(CaramagnaDeg1_cov,2))], ...
'orientation','vertical','location','eastoutside');
Gianluca Borgna
Gianluca Borgna 2019년 3월 26일
Thanks Rik! It's exactly what i wanted!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by