Histograms - Mean calculation - Comparing more pdf

2 Ansichten (letzte 30 Tage)
Gianluca Borgna
Gianluca Borgna am 25 Mär. 2019
Kommentiert: Gianluca Borgna am 26 Mär. 2019
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!

Akzeptierte Antwort

Rik
Rik am 25 Mär. 2019
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 Kommentare
Rik
Rik am 26 Mär. 2019
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 am 26 Mär. 2019
Thanks Rik! It's exactly what i wanted!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by