Finding number of data points in a single grid?
3 次查看(过去 30 天)
显示 更早的评论
I have a data set of consisting of latitude and longitude coordinates. After plotting my grid and the coordinate points, I want to determine the number of points within a single grid. This is my code so far. However, it can only create the grid and plot the points. It's unable to determine the number of points in a grid. Any idea why my code isn't doing what I want? Thanks in advance.
%%create grid
N = 31; % creates a 30x30 grid
xgrid = linspace(103.6,104,N);
ygrid = linspace(1.25,1.5,N);
[X,Y] = meshgrid(xgrid,ygrid);
figure
hold on
plot(X,Y,'r');
plot(X',Y','r');
xlim([103.6 104])
ylim([1.25 1.5])
%%plot coordinate points
plot(coordinates(:,2),coordinates(:,3),'.');
%%find number of bus stops in a single grid
lat = coordinates(:,2); % x coordinates
lon = coordinates(:,3); % y coordinates
% create nested for loop
for i = linspace(103.6,104,(1/75))
for j = linspace(1.25,1.5,(1/120))
% index = row number
index = find(lat > i & lat < i + 1 & lon > j & lon < j + 1);
% stn = data point
stn = coordinates(index,1);
end
end
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!