简体   繁体   English

Matlab中的2D数据合并

[英]2D data binning in matlab

I'm trying to bin some data with x and y coordinates however I am facing 2 challenges: 我正在尝试将一些数据与x和y坐标进行装箱,但是我面临2个挑战:

  1. bin width in x and y dimensions x和y尺寸的纸箱宽度
  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. 每个传感器在2D空间中获得目标的位置,但是由于读取错误,我从每个传感器获得的位置是不同的。 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 我想知道是否有人可以推荐一种可能的解决方案的方法,或者是一本有关分箱理论的书,以便使我对如何解决自己的问题有所了解

You can use histcounts2 to perform binning in 2D. 您可以使用histcounts2在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). 要获得箱位置,您可以将所有测量结果的2D空间都分成一个nxn网格(根据需要选择n)。 If the coordinates are saved in a 2 column matrix P 如果坐标保存在2列矩阵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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM