Use m_ map draw evenly spaced lines

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.

Réponses (1)

Nithin
Nithin le 25 Avr 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:

Catégories

En savoir plus sur Vector Fields dans Centre d'aide et File Exchange

Produits

Version

R2022a

Tags

Question posée :

ke
le 14 Déc 2022

Réponse apportée :

le 25 Avr 2025

Community Treasure Hunt

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

Start Hunting!

Translated by