OK.Hammouda
OK.Hammouda

Reputation: 1

2D data binning in matlab

I'm trying to bin some data with x and y coordinates however I am facing 2 challenges:

  1. bin width in x and y dimensions
  2. bin location ( where should the bin edge start)

I have some sensors that track a target. Each sensor gets the position of the target in 2D space, however due to reading errors, the position I get from each sensor is different. Therefore I would like to bin the readings and then maybe take the average of the readings in the bin to get the location of the target.

I was wondering if someone could recommend an approach to a possible solution or maybe a book about binning theory so that I could get an idea of how to tackle my problem

Upvotes: 0

Views: 2081

Answers (1)

Some Guy
Some Guy

Reputation: 1797

You can use histcounts2 to perform binning in 2D. To get bin locations you could take the 2D space of all your measurements and divide it in an nxn grid, (choose n as your wish). If the coordinates are saved in a 2 column matrix P

x = P(:,1); y = P(:,2)
xmax = max(x); xmin = min(x);
ymax = max(y); ymin = min(y);
N = 10; % Lets say number of bins we want
dx = (xmax - xmin) / (N-1);  dy = (ymax - ymin)/ (N-1); % N-1 will be clear in the next two lines
Xedges = xmin - dx/2 : dx : xmax + dx/2; % The outermost edges fall outside the range of data
Yedges = ymin - dy/2 : dy : ymax + dy/2; 
N = histcounts2(x,y,Xedges,Yedges)

Upvotes: 2

Related Questions