DJV
DJV

Reputation: 873

Plotting on a map

I'm plotting trajectories and right now, I just have figures with lines on it, corresponding to the list of LAT and LON that I brought in. How do I lay these trajectories over a map of the area that they're going over using the LAT and LON as limits on the map?

figure
for d = 1:i
hold on
plot(LON(d,:),LAT(d,:))
end
hold off

A picture of one such trajectory plot.

Upvotes: 2

Views: 940

Answers (1)

zinjaai
zinjaai

Reputation: 2385

The Matlab Mapping Toolbox is required for the following code.

LAT = [30, 40, 60];
LON = [-130, -90, -60]

coast_border = load('coast')  % Load coastline from Matlabs dataset
ax = worldmap('world')  % Create map figure
setm(ax, 'MapLatLimit', [min(LAT), max(LAT)], 'MAPLonLimit', [min(LON), max(LON)])
plotm(coast_border.lat, coast_border.long, 'k')  % Ploat coastline
plotm(LAT, LON, 'r')

Output

Note that you have to use setm instead of set if you want to change map settings.

Personally, i prefer to deactivate the Map-Grid and Labels and set the background color to blue

setm(ax,'meridianLabel','off','ParallelLabel','off','grid','off','ffacecolor',[0.6, 0.6, 1])

and fill the land

patchm(coast_border_lat, coast_border.long, [0.5 0.5 0.5])

Upvotes: 1

Related Questions