Hello Ash,
To plot a geomap with a 0.1-degree grid and use a color bar to show the number of occurrences of the latitude and longitude points from a text file, please follow these given (high-level) steps in MATLAB:
- Read the data from the text file.
- Create a grid with 0.1-degree resolution.
- Count the occurrences of latitude and longitude points in each grid cell.
- Plot the data on a geomap with a color bar.
Here's a complete example:
% Read the data from the text file
data = readmatrix('latlon.txt');
lats = data(:, 1);
lons = data(:, 2);
% Define the grid resolution
gridResolution = 0.1;
% Create the grid
latEdges = min(lats):gridResolution:max(lats);
lonEdges = min(lons):gridResolution:max(lons);
% Count occurrences in each grid cell
occurrences = histcounts2(lats, lons, latEdges, lonEdges);
% Create a figure
figure;
% Create a map with the specified grid resolution
latCenters = latEdges(1:end-1) + gridResolution/2;
lonCenters = lonEdges(1:end-1) + gridResolution/2;
% Plot the data using pcolor
pcolor(lonCenters, latCenters, occurrences);
shading flat;
colorbar;
xlabel('Longitude');
ylabel('Latitude');
title('Number of Occurrences of Lats and Lons');
% Optionally, use geoscatter for a more geographic visualization
% figure;
% geoscatter(lats, lons, [], occurrences(:), 'filled');
% colorbar;
% title('Number of Occurrences of Lats and Lons');
This code will create a geomap with a color bar indicating the number of occurrences of each latitude and longitude point within the specified grid cells.
Notes:
- Ensure that the text file "latlon.txt" is in the correct format and located in the current working directory or provide the full path to the file.
- Adjust the "gridResolution" if there is a need of different resolution.
- The "pcolor" function is used for plotting the grid data. If one prefers a geographic scatter plot, one can use "geoscatter" as shown in the commented section.
One can find more examples in the MathWorks Documentation for "contourm": Thematic Maps — Examples (mathworks.com)
Hope this helps!