contourm plotting

1 回表示 (過去 30 日間)
ash salut
ash salut 2012 年 3 月 17 日
回答済み: Sanchari 2024 年 7 月 25 日
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.

回答 (1 件)

Sanchari
Sanchari 2024 年 7 月 25 日
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!

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by