Move points on edges of 2d grid to closest bin centers , fails for big data?

1 次查看(过去 30 天)
This code moves all the points on top edge of 2D grid to center of closest bin and do the same for right edge of the grid,
Code works fine for commented data, but when I use big data it seems to fail, any thoughts ?
% x = [2,8,4,4.2,7.3,7.5,7.1,2,4.4,3.2,3.2,2,3.2,6,6.8,6.8,8]';
% y = [2,8,6,6.7,2.1,2.9,2.5,8,6.8,6.9,3.2,3.2,6.8,8,2,2,5]';
x = -5 + (5+5)*rand(100,1);
y = -3 +6*rand(100,1).^2;
xy = [x,y];
r = x;
s = y;
rs = [r,s];
numele = size(xy,1);
N =6;
mn_x = min(x);
mx_x = max(x);
mn_y = min(y);
mx_y = max(y);
dx = (mx_x - mn_x) / N;
dy = (mx_y - mn_y) / N;
xc = [mn_x+(dx/2):dx:mx_x-(dx/2)]; % Centers of bins.
yc = [mn_y+(dy/2):dy:mx_y-(dy/2)];
x_rng = linspace(mn_x,mx_x,N+1);
y_rng = linspace(mn_y,mx_y,N+1);
scatter(x,y,'b');
set(gca,'XTick', x_rng);
set(gca,'YTick', y_rng);
grid on;
hold on;
x(x ==y_rng(1,end)) = yc(1,end); % Move points on op edge to closet bin center.
y(y ==x_rng(1,end)) = xc(1,end); % Move points on top edge to closet bin center.
[p,q] = meshgrid(x_rng,y_rng);
scatter(x,y,'r','filled')

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dijkstra algorithm 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by