Finding number of data points in a single grid?

조회 수: 3 (최근 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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by