Binning in matlab

后端 未结 1 956
别跟我提以往
别跟我提以往 2021-02-05 22:55

I have been unable to find a function in matlab or octave to do what I want. I have a matrix m of two columns (x and y values). I know that I can extract the column by doing m(

相关标签:
1条回答
  • 2021-02-05 23:37

    I have answered this in video form on my blog:

    http://blogs.mathworks.com/videos/2009/01/07/binning-data-in-matlab/

    Here is the code:

    m = rand(10,2); %Generate data
    
    x = m(:,1); %split into x and y
    y = m(:,2);
    
    topEdge = 1; % define limits
    botEdge = 0; % define limits
    numBins = 2; % define number of bins
    
    binEdges = linspace(botEdge, topEdge, numBins+1);
    
    [h,whichBin] = histc(x, binEdges);
    
    for i = 1:numBins
        flagBinMembers = (whichBin == i);
        binMembers     = y(flagBinMembers);
        binMean(i)     = mean(binMembers);
    end
    
    0 讨论(0)
提交回复
热议问题