![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1826530/image.png)
How to draw streamline in a map?
7 views (last 30 days)
Show older comments
Hello! I want to ask how to draw some streamlines in a map by using the function 'streamslice' and the m_map package?
0 Comments
Answers (1)
Simran
8 minutes ago
I see you want to draw some streamlines in a map by using the “streamslice” and the “m_map” package. To do so follow these steps:
1.) Ensure you have the m_map package installed and added to your MATLAB path. You can refer to this link for help with this:
2.) If that is done, make sure you have your vector field data, in the form of “U” and “V” velocity matrices along with corresponding latitude and longitude grids.
3.) Next use the “m_map” package to create a map projection and display the base map.
4.) Use the “streamslice” function to overlay streamlines on the map.
Below I have used an example with some random data to show you how it works:
% Example Data
% Define a grid of latitude and longitude
lat = linspace(-10, 10, 100); % Latitude from -10 to 10 degrees
lon = linspace(-20, 20, 100); % Longitude from -20 to 20 degrees
[Lon, Lat] = meshgrid(lon, lat);
% Define synthetic vector field data (U, V)
% U and V represent the eastward and northward components of the velocity
U = cosd(Lat) .* sind(Lon); % Eastward component
V = sind(Lat) .* cosd(Lon); % Northward component
% Set up the map using m_map
m_proj('mercator', 'lat', [min(lat) max(lat)], 'lon', [min(lon) max(lon)]);
m_coast('patch', [0.7 0.7 0.7]); % Add coastlines with a gray patch
m_grid('box', 'fancy', 'tickdir', 'in'); % Add a grid with fancy box style
% Convert lat/lon to map coordinates
[X, Y] = m_ll2xy(Lon, Lat);
% Plot streamlines using streamslice
hold on;
h = streamslice(X, Y, U, V); % Plot streamlines
set(h, 'Color', 'r'); % Set streamline color to red
% Add additional plot elements if needed
title('Streamlines on Map');
And this was the result with streamlines on the map as you can see.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1826530/image.png)
For more information, you can refer to these documentations:
Adding folders to search path- https://www.mathworks.com/help/releases/R2021a/matlab/ref/addpath.html
“streamslice” documentation- https://www.mathworks.com/help/releases/R2021a/matlab/ref/streamslice.html
0 Comments
See Also
Categories
Find more on Weather and Atmospheric Science in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!