MATLAB: Generate a geographical heat map

mapping heat coordinates latitude longitude

Hello,
I am trying to generate a heat map on mapping toolbox.
Here I have the coordinates of the centers in my grid:
Lat = 54.2 + 0.1/6 * [11 9 7 5 3 1]' * ones(1,3) ;
Lon = 9.15 + 0.025 * ones(6,1) * [1 3 5] ;
coord = [ [Lat(:,1) , Lon(:,1)] ; [Lat(:,2) , Lon(:,2)] ; [Lat(:,3) , Lon(:,3)] ] ;
So coord is a 18 by 2 matrix, referring to the coordinates of 18 points.
Let us assume I want to assign a random value to each point, then I can define
values = rand(18, 1) .
How can I generate a heat map with such values in such locations?
How can I make each 'pixel' of the heat map like a sqare with size 0.05 by 0.033 degrees in longitude and latitude?
Thank you in advance for your help 🙂

Best Answer

I think this is what you're looking for.
heatmap
Note the change in inputs from matrix to vector of unique values.
rng('default') % for reproducibility


Lat = 54.2 + 0.1/6 * [11 9 7 5 3 1]';
Lon = 9.15 + 0.025 * [1 3 5]' ;
values = rand(18, 1);
valuesMatrix = reshape(values(:),numel(Lat),numel(Lon));
hm = heatmap(Lon,Lat,valuesMatrix);
imagesc with text labels
rng('default') % for reproducibility
Lat = 54.2 + 0.1/6 * [11 9 7 5 3 1]';
Lon = 9.15 + 0.025 * [1 3 5]' ;
values = rand(18, 1);
valuesMatrix = reshape(values(:),numel(Lat),numel(Lon));
figure()
h = imagesc(Lon, Lat, valuesMatrix);
% reproduce heatmap's colormap
n=256;
cmap = [linspace(.9,0,n)', linspace(.9447,.447,n)', linspace(.9741,.741,n)'];
colormap(cmap);
axis xy
colorbar()
hold on
% Add text labels
[xTxt, yTxt] = ndgrid(h.XData, h.YData);
labels = compose('%.4f', h.CData');
th = text(xTxt(:), yTxt(:), labels(:), ...
'VerticalAlignment', 'middle','HorizontalAlignment','Center');
geodensityplot & geoscatter for geoaxes
The types of graphics objects that can be plotted to geographic axes are limited. Some options are geobubble | geodensityplot | geoplot | geoscatter | geodensityplot; see the documentation for an updated list. The first two examples below use geodensityplot where each coordinate influences a radius of 3000 meters and the third demo uses geoscatter.
rng('default') % for reproducibility
Lat = 54.2 + 0.1/6 * [11 9 7 5 3 1]';
Lon = 9.15 + 0.025 * [1 3 5]' ;
values = rand(18, 1);
valuesMatrix = reshape(values(:),numel(Lat),numel(Lon));
[LatMatix, LonMatrix] = ndgrid(Lat,Lon);
figure()
tiledlayout(2,2)
nexttile
h = geodensityplot(LatMatix(:), LonMatrix(:), valuesMatrix(:),'Radius',3000);
nexttile
h = geodensityplot(LatMatix(:), LonMatrix(:), valuesMatrix(:),'Radius',3000,'FaceColor','interp');
nexttile
h = geoscatter(LatMatix(:), LonMatrix(:), 600, valuesMatrix(:), 'filled','Marker','s','MarkerFaceAlpha',.4);
[latlim, lonlim] = geolimits();
geolimits(latlim+(range(latlim)*.1),lonlim) % 10% lat axis increase