Why is my for loop outputting empty matrices?
Show older comments
This is a snippet of my current code to calculate the number of data points in a single grid. "i = [103.6:(1/75):104]" represents the x axis values of each vertical grid line, "j = [1.25:(1/120):1.5]" represents the y axis values of each horizontal grid line. "coordinates" is a n x 3 numeric matrix that contains the station number, lat coordinates, and lon coordinates. I'm trying to find the row number of all the stations that fall in a single grid. Is there something wrong with my code? It keeps producing empty matrices for "index" and "stns". Safe to say it's not producing anything at all.
Also, in my find function, does (i + 1) represent the next value in the i vector or am I adding a value of 1 to the current value of i? I'm new to Matlab so I apologize if my questions come off as a bit silly. Thanks in advance!
lat = coordinates(:,2); % x coordinates
lon = coordinates(:,3); % y coordinates
% create nested for loop
for i = [103.6:(1/75):104]
for j = [1.25:(1/120):1.5]
% index = row number
index = find(lat > i & lat < i + 1 & lon > j & lon < j + 1);
stns = coordinates(index,1); % stn number
end
end
1 Comment
Accepted Answer
More Answers (1)
Jan
on 30 May 2017
0 votes
Categories
Find more on Just for fun in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!