Finding number of data points in a single grid?

2 ビュー (過去 30 日間)
Atiqah Zakirah
Atiqah Zakirah 2017 年 5 月 30 日
コメント済み: Atiqah Zakirah 2017 年 5 月 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

回答 (1 件)

Musa
Musa 2017 年 5 月 30 日
Atiqah,
coordinates isn't defined.
  1 件のコメント
Atiqah Zakirah
Atiqah Zakirah 2017 年 5 月 30 日
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?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by