MATLAB: Some questions with histograms

histogrammode

Greetings all,
I have 3 questions about the attached histogram.
1.) When I use MATLAB's mode command in my code, it does not match the output for this histogram. What I mean by that is, since the mode is defined as being the most common element of an array, according to that histogram, it should be in the 70-80 bin range, not 1.0329 as per MATLAB's mode output.
Code for that is (just in case):
mode_Sigma1=mode(OutputMatrixValid(1:numtrue,48));
where (OutputMatrixValid(1:numtrue,48)) is all of the Sigma1 values. Did I do something wrong or is there a bug in MATLAB's mode command?
2.) Is there anyway to "shade" histograms by confidence interval/percentile (did a web search and no luck)? For instance, the black lines represent the 95% CI, blue lines are the 25%/75%, and the green lines are the 68% (i.e., +/- the standard deviation). By shading, I mean shading the bars of the histogram that are in these CI ranges. Is there any way to do that?
3.) Is there any way to create a "stacked" histogram in MATLAB (did a web search and again no luck)? These Sigma1 values were generated by the following function call and code:
function [sigma1 sigma2] = CalculateSigma1and2(sigmaa, sigmab, ra0, rb0, ra1, rb1)
n = 1;
for i = 1:length(sigmaa)
for j = 1:length(sigmab)
sigma1(n) = (sigmaa(i)*rb1(j) -sigmab(j)*ra1(i))/(ra0(i)*rb1(j) - rb0(j)*ra1(i));
sigma2(n) = (sigmaa(i)*(rb0(j)-rb1(j)) - sigmab(j)*(ra0(i)-ra1(i)))/(ra1(i)*rb0(j) - rb1(j)*ra0(i));
n = n + 1;
end
end
end
So there are multiple inputs to calculate Sigma1, but luckily the "sigmaa" and "sigmab" are values based on location pairs between two instruments that I have in an array, like so:
sigma_a = [EM31West; EM31East; GSSIWest; GSSIEast];
So, back to my original question (apologies if too much detail was presented, but I'd rather go with too much than not enough), is there a way to make a stacked histogram such that, the bins have one color for the Sigma1's generated from EM31West vs. EM31East, and another color for GSSIWest vs. EM31East, etc. Again, this is based on location pairs to calculate Sigma1 in the first place.
Thanks! Jesse

Best Answer

The histogram counts values in a range, the mode counts occurrences of numbers. So for example, if X = [1 1 1 11 11 12 13 14 15], the histogram peaks for the bin 11-20 (provided you have bins 1-10, 11-20), but the mode is 1. That's fine.