【问题标题】:Identify items in each grid using MATLAB使用 MATLAB 识别每个网格中的项目
【发布时间】:2015-10-06 23:58:26
【问题描述】:

我有refxy 大小500 x 3 的数据集,其中每一行代表一个位置,使得第一、第二和第三列具有x 坐标、y 坐标和该位置的weight v1。使用以下代码,我将此区域划分为14 x 18 网格,然后我找到每个网格中有多少点输出blockNums_v1

function gridcounttest
load refxy

x = refxy(:,1);
y = refxy(:,2);
v1 = refxy(:,3);

 nBinsX = 14 ;
 nBinsY = 18 ;
 xg     = linspace( 0, 700, nBinsX+1 ) ;
 yg     = linspace( 0, 900, nBinsY+1 ) ;
 nCells = nBinsX * nBinsY ;

 xId = sum( bsxfun( @ge, x, xg(1:end-1) ), 2 ) ;
 yId = sum( bsxfun( @ge, y, yg(1:end-1) ), 2 ) ;
 cellId = nBinsY * (xId - 1) + yId ;

 blockNums_v1  = accumarray( cellId, 1, [nCells, 1] ) 
 blockSum_v1  = accumarray( cellId, v1, [nCells, 1] ) 
 blockMean_v2 = accumarray( cellId, v1, [nCells, 1], @mean )

谁能帮我确定每个网格中包含哪些点,可能是行号?例如,如果 10 号网格有 3 个点,分别位于第 23、51 和 432 行。这段代码给出了输出 3,但不是我现在需要得到的 23、51、432 :)

谢谢!!!

【问题讨论】:

标签: matlab data-analysis


【解决方案1】:

您可以通过

找到网格元素中的点行
rowsOfValuesInGridpoint10 = find(cellId == 10);

问题是输出不均匀,当你想找到几个网格元素的点时。

您可以将行存储在 Matlab 单元格中,例如

for i=1:nCells
 rowsInThisElement{i} = find(cellId == i);
end
rowsInThisElement{10}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-20
    • 2018-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-23
    • 2012-02-29
    • 2012-02-20
    相关资源
    最近更新 更多