generate heat map based on lat/lon and data value

Hello,
I have a table with Lat/Lon and some error values. I would like to plot the lat/long and create a heatmap using the error value.
lat lon err_d
38.53 -77.40 194.4729
38.75 -77.04 147.9679
39.05 -77.91 340.3928
any help would be greatly appreciated.
Best,
KB

6 Comments

table has 818970 different values of lat/lon and error.
I looked at the link provided but wasn't sure how it was putting everything in a matrix form and I got an error on the reshape command.
rng('default') % for reproducibility
Lat = July1st.lat_t;
Lon = July1st.lon_t ;
values = July1st.err_d;
valuesMatrix = reshape(values(:),numel(Lat),numel(Lon)); %MARKED
[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
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for
that dimension.
It sounds to me as if you might have "scattered" Lat and Lon, instead of effectively having a grid of them?

Sign in to comment.

 Accepted Answer

Let T be your grid...
x = T.lon ;
y = T.lat ;
z = T.err_d ;
% Convert the scattered data into grid
m = 100 ; % can be increased
[X,Y] = meshgrid(linspace(min(x),max(x),m),linspace(min(y),max(y),m)) ;
Z = griddata(x,y,z,X,Y) ;
pcolor(X,Y,Z)
shading interp
colorbar

More Answers (1)

The heatmap function accepts a table as input, this should be a one-liner. If you are looking for a surface plot, KSSV's answer should work.

Categories

Community Treasure Hunt

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

Start Hunting!