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

38 views (last 30 days)
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.
  2 Comments
Greg B.
Greg B. on 5 Aug 2015
Thank you Kelly. What I did was this:
lat = flipud(load('Grid')) %LATITUDE
lon = load('Grid')
[LAT LON] = meshgrid(lat,lon);
Where LAT and LON are both 51X51 matrices, except LAT is flipped. I wish to now just plot points, such that cell (1,1) of lat plots with cell (1,1) of LON, and so on. Do you have an idea about where to start?
Thank you.
Kelly Kearney
Kelly Kearney on 5 Aug 2015
Please add your responses to the relevant answer; it makes threads much easier to follow. I've duplicated this and will respond in my answer below.

Sign in to comment.

Accepted Answer

Kelly Kearney
Kelly Kearney on 5 Aug 2015
You'll want to use meshgrid or ndgrid to expand the vectors:
[lat, lon] = meshgrid(-14:0.5:14);
ltln = [lat(:) lon(:)]
  1 Comment
Kelly Kearney
Kelly Kearney on 5 Aug 2015
Greg commented:
Thank you Kelly. What I did was this:
lat = flipud(load('Grid')) %LATITUDE
lon = load('Grid')
[LAT LON] = meshgrid(lat,lon);
Where LAT and LON are both 51X51 matrices, except LAT is flipped. I wish to now just plot points, such that cell (1,1) of lat plots with cell (1,1) of LON, and so on. Do you have an idea about where to start?
Thank you.
----------------
The flip seems a bit unnecessary; if you're pairing every longitude with every latitude, the order is somewhat irrelevant. But it doesn't hurt, I guess.
I suggest you read through the "Getting Started" portion of the documentation to familiarize yourself with various plotting techniques. If you simply want to plot a dot at each grid point:
plot(LAT, LON, 'k.');
Though I'm guessing you probably want to plot some data values at each point, so perhaps you should investigate surf, mesh, pcolor, contour, etc.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!