Finding number of data points in a single grid?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!