Multiple geoplot lines with one call
30 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I'm trying to plot multiple lines with geoplot but I think I'm missing something with the geoplot notation. Supposing I want to plot only two lines:
from = [48 2]; % Longitude, Latitude
toA = [52 13]; % Longitude, Latitude
toB = [41.7 12.5]; % Longitude, Latitude
I can use:
geoplot([from(1) toA(1)],[from(2) toA(2)],[from(1) toB(1)],[from(2) toB(2)]);
which already seems quite complicated. What if I want to plot more lines? I would expect something like
lonFrom = [48; 48; 48]; % Longitude From
latFrom = [2; 2; 2]; % Latitude From
lonTo = [52; 41.7; 40]; % Longitude To
latTo = [13; 12.5; -3.5]; % Latitude To
geoplot([lonFrom lonTo],[latFrom latTo]) % ERROR
to work, but it doesn't. Apparently geoplot only works line by line meaning with vectors for longitude and latitude and no matrices. Is this true? Do I have to explicitly give longitude and latitude coordinates for every single line?
geoplot([lonFrom(1) lonTo(1)],[latFrom(1) latTo(1)],...
[lonFrom(2) lonTo(2)],[latFrom(2) latTo(2)],...
[lonFrom(3) lonTo(3)],[latFrom(3) latTo(3)]); % Works but impractical for multiple lines
It would be a nightmare to plot 5, 10 or 100 lines. A loop would somewhat do the trick, but I would like to have all the lines in one handle. Am I missing something? Shouldn't geoplot be able to accept and interpret matrices as input?
0 Kommentare
Antworten (2)
Rob Comer
am 22 Dez. 2021
You can use plot() to plot matrices in a geographic axes
Any easy workaround is to (a) create a GeographicAxes object and (b) add lines to it using the plot function instead of the geoplot function.
But first a quick correction: It looks like you want to connect each of 3 points to a common point at (lat=2, lon=48). However, plot creates a line for each column in the input matrices, not each row, so I think you have your inputs transposed. Starting again, and forming 2x3 matrices LAT and LON, we have:
lonFrom = [48 48 48]; % Longitude From
latFrom = [2 2 2]; % Latitude From
lonTo = [52 41.7 40]; % Longitude To
latTo = [13 12.5 -3.5]; % Latitude To
LON = [lonFrom; lonTo];
LAT = [latFrom; latTo];
For reference, here are the lines in an ordinary axis using plot:
figure
plot(LON,LAT)
Finally, create a GeographicAxes in advance using geoaxes, then pass it to plot as the first input:
figure
gx = geoaxes;
plot(gx,LAT,LON)
Note: Latitude comes before longitude when plotting into a GeographicAxes, whether using geoplot or plot (or line, geoscatter, scatter, or text).
0 Kommentare
Cris LaPierre
am 26 Apr. 2021
Bearbeitet: Cris LaPierre
am 26 Apr. 2021
Use the documentation to determine what valid input arguments are. Your observation is correct - geoplot currently only supports vectors as inputs for lat and lon.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Geographic Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!