Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 在三维直方图网格上寻找给定点的归属值?_Matlab_Search_Histogram_Interpolation - Fatal编程技术网

Matlab 在三维直方图网格上寻找给定点的归属值?

Matlab 在三维直方图网格上寻找给定点的归属值?,matlab,search,histogram,interpolation,Matlab,Search,Histogram,Interpolation,我使用二维数据集,如下所示 37.0235000000000 18.4548000000000 28.4454000000000 15.7814000000000 34.6958000000000 20.9239000000000 26.0374000000000 17.1070000000000 27.1619000000000 17.6757000000000 28.4101000000000 15.9183000000000 33.73400000000

我使用二维数据集,如下所示

37.0235000000000    18.4548000000000
28.4454000000000    15.7814000000000
34.6958000000000    20.9239000000000
26.0374000000000    17.1070000000000
27.1619000000000    17.6757000000000
28.4101000000000    15.9183000000000
33.7340000000000    17.1615000000000
34.7948000000000    18.2695000000000
34.5622000000000    19.3793000000000
36.2884000000000    18.4551000000000
26.1695000000000    16.8195000000000
26.2090000000000    14.2081000000000
26.0264000000000    21.8923000000000
35.8194000000000    18.4811000000000
创建三维直方图

如何在网格上找到点的直方图值?例如,如果给定了
[34.794800000000 18.2695000000]
点,我希望找到网格上给定点的直方图的对应值

你可以用它来完成


如果
X
(一维向量,长度N)和
Y
(一维向量,长度M),确定直方图定义值的轴上的离散坐标
Z
(矩阵,大小MXN)。使用坐标(
XI
YI
)获取一个特定点的值可以通过以下方法完成:

% generate grid
[XM, YM] = meshgrid(X, Y);
% interpolate desired value
ZI = interp2(XM, YM, Z, XI, YI, 'spline')
一般来说,这类问题是插值问题。如果您想获得多个点的值,则必须以上面代码中所述的类似方式为它们生成网格。您还可以使用另一种插值方法,例如
linear
(请参阅链接文档!)

您可以使用它来实现这一点


如果
X
(一维向量,长度N)和
Y
(一维向量,长度M),确定直方图定义值的轴上的离散坐标
Z
(矩阵,大小MXN)。使用坐标(
XI
YI
)获取一个特定点的值可以通过以下方法完成:

% generate grid
[XM, YM] = meshgrid(X, Y);
% interpolate desired value
ZI = interp2(XM, YM, Z, XI, YI, 'spline')
一般来说,这类问题是插值问题。如果您想获得多个点的值,则必须以上面代码中所述的类似方式为它们生成网格。您还可以使用另一种插值方法,例如
linear
(请参阅链接文档!)

我使用了这段代码

point = feat_vec(i,:); // take the point given by the data set
X = centers{1}(1,:); // take center of the bins at one dimension
Y = centers{2}(1,:); // take center of the bins at other dim.  

distanceX = abs(X-point(1)); // find distance to all bin centers at one dimension 
distanceY = abs(Y-point(2)); // find distance to center points of other dimension

[~,indexX] = min(distanceX); // find the index of minimum distant center point
[~,indexY] = min(distanceY); // find the index of minimum distant center point for other dimension
我用了这个密码

point = feat_vec(i,:); // take the point given by the data set
X = centers{1}(1,:); // take center of the bins at one dimension
Y = centers{2}(1,:); // take center of the bins at other dim.  

distanceX = abs(X-point(1)); // find distance to all bin centers at one dimension 
distanceY = abs(Y-point(2)); // find distance to center points of other dimension

[~,indexX] = min(distanceX); // find the index of minimum distant center point
[~,indexY] = min(distanceY); // find the index of minimum distant center point for other dimension
我想你的意思是:

[N,C]=hist3(X,…)返回存储单元中存储单元中心的位置 数字向量的1×2单元格数组,不绘制直方图

这就是说,如果你有一个2D点
x=[x1,x2]
,你只需要在
C
中查找最近的点,并在N中取相应的值

在Matlab代码中:

[N, C] = hist3(data); % with your data format...
[~,indX] = min(abs(C{1}-x(1)));
[~,indY] = min(abs(C{2}-x(2)));
result = N(indX,indY);
完成了。(你可以把它变成你自己的函数,比如说
result=hist\u val(data,x)


编辑:

我刚刚看到,我的答案本质上只是@Erogol答案的更详细版本。

我想你的意思是:

[N,C]=hist3(X,…)返回存储单元中存储单元中心的位置 数字向量的1×2单元格数组,不绘制直方图

这就是说,如果你有一个2D点
x=[x1,x2]
,你只需要在
C
中查找最近的点,并在N中取相应的值

在Matlab代码中:

[N, C] = hist3(data); % with your data format...
[~,indX] = min(abs(C{1}-x(1)));
[~,indY] = min(abs(C{2}-x(2)));
result = N(indX,indY);
完成了。(你可以把它变成你自己的函数,比如说
result=hist\u val(data,x)


编辑:

我刚刚看到,我的答案本质上只是@Erogol答案的更详细版本