values in falling in each histogram bin

Hello,
sig=randn(1,440); %random data set
bin1=round(1+log2(size(sig,2))); %optimal number of bins
edges = linspace(min(sig), max(sig), bin1+1);
bins = (edges(1:end-1) + edges(2:end))/2;
[counts,binIdx] = histc(sig, edges); %bin count
counts(end) = []; %remove the additional added bin
binIdx(binIdx==bin1+1) = bin1; %set the index
figure; hist(sig,bin1) %plot histogram
How do I find the values of sig falling in each bin? My final goal is to have only those values from 'sig' in a variable which are below a count of (say 20) in the histogram.
please help

답변 (1개)

José-Luis
José-Luis 2012년 8월 21일

1 개 추천

sig=randn(1,440); %random data set
bin1=round(1+log2(size(sig,2))); %optimal number of bins
edges = linspace(min(sig), max(sig), bin1+1);
bins = (edges(1:end-1) + edges(2:end))/2;
[n,xOut]= hist(sig,bins); %or use histc if you want to specify the edges.
n is the vector of values you are looking for.
Cheers!

댓글 수: 7

zozo
zozo 2012년 8월 21일
@Jose: xOut only has center values located in each bin(vector of size equal to bin1). Iam looking for ALL values which fall in each bin(due to historgam) from the input data vector sig
for example: If I have 10 bins and say first bin has count=11 and second bin has a count=19. Now I want a vector of all values in each of these bins (11+19=30), belonging to the sig in a vector as my output.
Maybe
cumsum(xOut);
zozo
zozo 2012년 8월 21일
does not work :(
Sorry, i meant:
cumsum(n); %n is a vector with the number of values in each bin
For more details, look at the documentation (help hist or help histc).
zozo
zozo 2012년 8월 22일
I got till there. I want to extract the actual values falling in each of the bins(not the count in each bin).
sig=randn(1,440); %random data set
bin1=round(1+log2(size(sig,2))); %optimal number of bins
edges = linspace(min(sig), max(sig), bin1+1);
bins = (edges(1:end-1) + edges(2:end))/2;
PointsInBin = cell(length(edges) - 1,1);
PointsInBin(1) = {sig(sig>= edges(1) & sig<=edges(2))};
for k = 3:length(edges)
PointsInBin(k-1) = {sig(sig>edges(k-1) & sig <= edges(k))};
end
zozo
zozo 2012년 8월 22일
편집: zozo 2012년 8월 22일
@Jose: Thank you. I have simplified it further:
sig=randn(1,440); %random data set
bin1=round(1+log2(size(sig,2))); %optimal number of bins
edges = linspace(min(sig), max(sig), bin1+1);
bins = (edges(1:end-1) + edges(2:end))/2;
[n,whichbin]= histc(sig,edges);
PointsInBin=cell(length(edges)-1,1);
for k=1:bin1
flagBinMem=(whichbin==k);
PointsInBin(k)={sig(flagBinMem)};
end

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

태그

질문:

2012년 8월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by