(Solved) How to plot the variance of elements in each bin of histogram?

22 次查看(过去 30 天)
Data: Array of real valued numbers. (say XArray)
To plot: A histogram superimposed with the plot of variance(/IQR) of elements
in each bin.
Also, how could i plot frequency on x-axis instead of y-axis.
Sincerely
  1 个评论
gunjanthesystem
gunjanthesystem 2014-3-25
编辑:gunjanthesystem 2014-3-25
(Solution) using histc to get 'binIndex', i,e. the bin index of each element in the data array. Bin index indicates in which bin that particular element was put.
[~,binIndex]= histc(XArray,binranges);
varMatrix=zeros(1,numberOfBins); % filled with dummy values
for iterator=1:max(binIndex)
varMatrix(iterator)=var(XArray(find(binIndex==iterator)));
end
%Now the varMatrix will contains the variance for each bin.

请先登录,再进行评论。

回答(2 个)

Chandrasekhar
Chandrasekhar 2014-3-24
plot the histogram using hist command then hold the figure using hold on. then plot the variant using plot command
hist(array)
hold
plot(frequency,variance)

Image Analyst
Image Analyst 2014-3-24
To get the counts:
counts = hist(data, numberOfBins);
To get the variance of the counts
countVariance = var(counts);
  2 个评论
gunjanthesystem
gunjanthesystem 2014-3-24
Hi, thanks, But that not what I am looking for. your answer will give the variance of the 'counts of bins'.
I need the variance of the 'elements in each bin'. The elements are numeric. It can only be done if there is way to access the elements put in each bin and not just 'how many element are in each bin (count)'
Image Analyst
Image Analyst 2014-3-24
You need to know the value that defines the start and stop value for each bin. Let's say it's v1 and v2. Then extract all the values in that range from your data
inRange = data > v1 & data < v2;
Now get the variance
dataRangeVariance = var(data(inRange));
This gets the variance of only those elements that fell into that particular bin.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by