Finding number of data points in a single grid?

2 vues (au cours des 30 derniers jours)
Atiqah Zakirah
Atiqah Zakirah le 30 Mai 2017
Commenté : Atiqah Zakirah le 30 Mai 2017
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

Réponses (1)

Musa
Musa le 30 Mai 2017
Atiqah,
coordinates isn't defined.
  1 commentaire
Atiqah Zakirah
Atiqah Zakirah le 30 Mai 2017
Hey Musa,
My coordinates were from an excel file. I imported the data into Matlab as a numeric matrix called "coordinates" so there isn't a line of code that defines what the coordinates are since there's too many. Must I define it in another way?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by