contourm plotting

1 Ansicht (letzte 30 Tage)
ash salut
ash salut am 17 Mär. 2012
Beantwortet: Sanchari am 25 Jul. 2024
I have a text file containing Lats and Lons. I want to plot a geomap with 0.1 deg grid. Then the map use a color bar, showing the number of occurrences of the Lats and Longs.

Antworten (1)

Sanchari
Sanchari am 25 Jul. 2024
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:
  1. Read the data from the text file.
  2. Create a grid with 0.1-degree resolution.
  3. Count the occurrences of latitude and longitude points in each grid cell.
  4. 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!

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by