Hi,
I understand that you want to plot the latitudes and longitudes onto the map axes.
For such large variables of "X", "Y", and "Z", I suggest creating a meshgrid of lon and lat coordinates first. Then, you can use the "pcolorm" function to plot the "Z" variable on the map.
Additionally, you use the "scaleruler" function to add a scale bar to the frame.
Here's an updated version of your code incorporating the above suggestions:
clf
axesm('MapProjection', 'mercator')
% Create a meshgrid of lon and lat coordinates
[lon_grid, lat_grid] = meshgrid(x, y);
% Plot the Z variable using pcolorm
pcolorm(lat_grid, lon_grid, z);
S = shaperead('study_site.shp', 'UseGeoCoords', true);
info = shapeinfo('study_site.shp');
crs = info.CoordinateReferenceSystem;
geoshow(S, 'FaceColor', 'white');
% Adjust axes limits if needed
% xlim([lon_min, lon_max]);
% ylim([lat_min, lat_max]);
% Add scale bar
scaleruler('RulerStyle', 'patches', 'Units', 'km', 'FontSize', 10);
% Add latitude and longitude information to the frame
framem on;
gridm on;
mlabel on;
plabel on;
To find more about the functions used here, kindly refer to the following documentation pages:
- 2-D and 3-D grids - MATLAB meshgrid (mathworks.com)
- Project geolocated data grid in h = 0 plane on axesm-based map - MATLAB pcolorm (mathworks.com)
- Add or modify graphic scale on axesm-based map - MATLAB scaleruler (mathworks.com)
- Map Customization - MATLAB & Simulink (mathworks.com)
Hope the above information resolves your issue.
Regards,
Harshit