Hi Briana,
I understand that you are trying to create a heat map to show the frequency of coordinate points that occurred in a tile.
To do so, you can follow the given steps:
- Initialize a matrix of zeros with dimensions equal to the number of latitude tiles and the number of longitude tiles using:
valuesMatrix = zeros(numel(Lat_tile), numel(Lon_tile));
This matrix will store the count of data points falling within each tile.
2. Create a nested for loop, that iterates over each “latitude(i)” and “longitude(j)” tile:
a. Create a logical index “tileIndices” that identifies the data points falling within the current tile in this manner:
tileIndices = Lat >= tileLat & Lat < tileLat + 0.18 & Lon >= tileLon & Lon < tileLon + 0.25;
b. Calculates the sum of “tileIndices” (number of data points falling within the current tile) and assigns it to the corresponding position in “valuesMatrix”.
valuesMatrix(i, j) = sum(tileIndices);
3. Plot the heatmap using:
heatmap(Lon_tile, Lat_tile, valuesMatrix);
Here “Lon_tile” and “Lat_tile” represent the longitude and latitude ranges of the tiles, respectively, and "valuesMatrix” contains the count of data points falling within each tile. The resulting heatmap will show the density of data points in each tile without overlapping as seen in the image.
You can modify your code by referring to this:
% Create a heatmap without overlapping tiles
Lat_tile = 54.82 + 0.18 * (19:-2:1)';
Lon_tile = -123.25 + 0.25 * (1:2:11)';
% Calculate the values matrix for heatmap
valuesMatrix = zeros(numel(Lat_tile), numel(Lon_tile));
for i = 1:numel(Lat_tile)
for j = 1:numel(Lon_tile)
tileLat = Lat_tile(i);
tileLon = Lon_tile(j);
tileIndices = Lat >= tileLat & Lat < tileLat + 0.18 & Lon >= tileLon & Lon < tileLon + 0.25;
valuesMatrix(i, j) = sum(tileIndices);
end
end
% Plot the heatmap
figure
heatmap(Lon_tile, Lat_tile, valuesMatrix);
title('Heatmap of Reports per Tile');
xlabel('Longitude');
ylabel('Latitude');
For more information on the “heatmap” function, please refer to the following link:
Hope this helps!
Regards,
Ayush.