Search code examples
matlabbinbinning

How to use binning method for identifying the incoming point belongs to which bin?


I have small query. I have two data sets. In one data sets for example I did binning and calculated the mean value and std value along with group binning. Now in I have second data sets of same parameters say X. I would like identify this X data sets belong to which bin groups of my previous data sets using matlab.

Could you give some example how to identify the incoming data points belongs to which bin group...??

I used following binning which is available in matlab :

  binEdges = linspace(botEdge, topEdge, numBins+1);
  [h,whichBin] = histc(x, binEdges);

Solution

  • Well... you already have your bin edges. Anything inside specific edges is in that bin.

    If you know that the data is inside the ranges you defined then, for each new data

    newdatabin=find(newdata>binedges,1,'last'); %this is the bin number where the new data goes in
    
    h(newdatabin)=h(newdatabin)+1; %add one!
    

    Also consider using histcounts if your MATLAB version is new enough.