Use m_ map draw evenly spaced lines

조회 수: 2 (최근 30일)
ke
ke 2022년 12월 14일
답변: Nithin 2025년 4월 25일
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.

답변 (1개)

Nithin
Nithin 2025년 4월 25일
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:

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by