MATLAB: Creating a Grid of Lat/Lon Values, in two columns

repmat

Howdy.
The first thing I'm trying to do is take a vector lat = [-14:0.5:14] and a vector lon = [-14:0.5:14], and make a 3249X2 matrix such that I have:
-14 -14
-14 -13.5
-14 -13.0
.
.
.
14 13.0
14 13.5
14 14
So I should have 3249 rows and 2 columns, where each latitude value matches with a respective longitude value. I have tried using repmat, but that didn't quite work. Does anyone have any ideas on how to do this?
Thanks for your help.

Best Answer

You'll want to use meshgrid or ndgrid to expand the vectors:
[lat, lon] = meshgrid(-14:0.5:14);
ltln = [lat(:) lon(:)]