How label data points using text within a for loop

9 views (last 30 days)
I am trying to produce a map of tide gauges using Geoscatter and then label each tide gauge with its corresponding tide gauge number. I have an array, A, that contains 58 tide guages - each one with it's own tide gauge number. I also have arrays for longitude and latitude that corresponds to each tide gauge number. So far, I have got this:
load('A.mat');
load('PSMSL+ERA5IB.mat');
geoscatter(Latitude(A),Longitude(A),20)
for i=1:58
text(Longitude(A(i)),Latitude(A(i)),string(A(i)));
end
This produces a map, but doesn't give the labels for the tide gauges. I'm not sure why

Answers (1)

Eric Delgado
Eric Delgado on 22 Mar 2023
It seems that you have to create a custom data tips...
rawData = table([-13;-30], [-39; -39], ["ID 1"; "ID 2"], 'VariableNames', {'lat', 'long', 'label'})
rawData = 2×3 table
lat long label ___ ____ ______ -13 -39 "ID 1" -30 -39 "ID 2"
figure
h = geoscatter(rawData.lat, rawData.long);
h.DataTipTemplate.DataTipRows(end+1) = dataTipTextRow('Label', rawData.label);
datatip(h, -13, -39);
datatip(h, -30, -39);

Categories

Find more on Characters and Strings 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!