Use m_ map draw evenly spaced lines

4 views (last 30 days)
ke
ke on 14 Dec 2022
Answered: Nithin on 25 Apr 2025
If an image is divided into 300×300 points, and the data of each point is known. The x-axis and y-axis coordinates of the image are longitude and latitude. How to correspond the points with longitude and latitude, and how to connect the points of the same data. Draw evenly spaced lines at 20 intervals.

Answers (1)

Nithin
Nithin on 25 Apr 2025
Hi @ke,
To create the graph you described, you can use meshgrid to align your grid data with longitude and latitude, and m_contour to draw contours at regular intervals. Here’s a step-by-step outline of the process::
  • Generate longitude and lattitude grids
lon_min = ...; % e.g., 100
lon_max = ...; % e.g., 110
lat_min = ...; % e.g., 20
lat_max = ...; % e.g., 30
lon = linspace(lon_min, lon_max, 300);
lat = linspace(lat_min, lat_max, 300);
[Lon, Lat] = meshgrid(lon, lat); % size(Lon) = [300, 300]
  • Setup "m_map" projection
figure
m_proj('mercator', 'lon', [lon_min lon_max], 'lat', [lat_min lat_max]);
m_grid('box','fancy','tickdir','in');
hold on
  • Draw evenly spaced contour lines
interval = 20;
min_val = floor(min(data(:))/interval)*interval;
max_val = ceil(max(data(:))/interval)*interval;
v = min_val:interval:max_val;
[~, h] = m_contour(Lon, Lat, data, v, 'k'); % 'k' for black lines
clabel(_, h); % Optional: Add contour labels
Refer to the following documentations to know more about the functions used:

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Tags

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!