bin data from a line profile into in matlab

To bin data from a line profile in MATLAB, you can use the accumarray function. Assuming you have a vector lineProfile containing your data and you want to bin it into numBins bins, you can do the following:

main.m
% Example data
lineProfile = rand(1, 100); % random line profile data
numBins = 10;

% Determine which bin each data point belongs to
binIndices = ceil((1:numel(lineProfile)) / (numel(lineProfile) / numBins));

% Bin the data
binnedData = accumarray(binIndices(:), lineProfile(:), [], @mean);

% If you want to store the count of data points in each bin
counts = accumarray(binIndices(:), 1, [], @sum);
403 chars
13 lines

In this example, binnedData will contain the mean of the data points in each bin, and counts will contain the count of data points in each bin. You can adjust the binning method (e.g., sum, median, etc.) by changing the function handle used in accumarray.

related categories

gistlibby LogSnag