numLatCells = length(latGrid) - 1;
numLonCells = length(lonGrid) - 1;
classCountsInGridCell = cell(numLatCells, numLonCells);
actualCellSize = 1 / (111.32 * 1000);
cellSizeLat = (latLimits(2) - latLimits(1)) / numLatCells;
cellSizeLon = (lonLimits(2) - lonLimits(1)) / numLonCells;
gridMatrix = zeros(numLatCells, numLonCells, 'int16');
latGrid = linspace(latLimits(1), latLimits(2), numLatCells + 1);
lonGrid = linspace(lonLimits(1), lonLimits(2), numLonCells + 1);
inGridCell = lat >= latGrid(i) & lat < latGrid(i+1) & lon >= lonGrid(j) & lon < lonGrid(j+1);
latPolygon = [latGrid(i), latGrid(i+1), latGrid(i+1), latGrid(i), latGrid(i)];
lonPolygon = [lonGrid(j), lonGrid(j), lonGrid(j+1), lonGrid(j+1), lonGrid(j)];
geoplot(ax, latPolygon, lonPolygon, 'Color', 'k', 'LineWidth', 1, 'HandleVisibility', 'off');
boxCenterLat = (latGrid(i) + latGrid(i+1)) / 2;
boxCenterLon = (lonGrid(j) + lonGrid(j+1)) / 2;
distanceToSummit = deg2km(distance(summitLat, summitLon, boxCenterLat, boxCenterLon));
text(boxCenterLat, boxCenterLon, sprintf('%.2f km', distanceToSummit), 'Color', 'red', 'HorizontalAlignment', 'center');
if ~isempty(classAttributesInGridCell{i, j})
cellClassAttribute = classAttributesInGridCell{i, j};
[cellUniqueClasses, cellClassCounts] = uniqueCount(cellClassAttribute);
fprintf('Grid %d:\n', gridCounter);
fprintf('Class Counts:\n');
for k = 1:numel(uniqueClasses)
classIndex = find(strcmp(cellUniqueClasses, uniqueClasses(k)));
fprintf('%s: %d\n', uniqueClasses{k}, 0);
fprintf('%s: %d\n', uniqueClasses{k}, cellClassCounts(classIndex));
fprintf('Grid %d:\n', gridCounter);
fprintf('No data points in this grid cell.\n\n');
gridCounter = gridCounter + 1;