How to add map to an output

1 次查看(过去 30 天)
I am trying to add the output to a map but i can't figure out how to add it.
  7 个评论
Sangesh Pv
Sangesh Pv 2023-9-29
% Load your data
data = readmatrix('subtowersutm.xlsx');
% Extract latitude, longitude, and RSRP values.
measurement_lat = data(:, 1);
measurement_lon = data(:, 2);
rsrp = data(:, 11); % Adjust the column index for RSRP data.
% Check if the dimensions of Lat and Lon match
if size(measurement_lat) ~= size(measurement_lon)
error('Latitude and Longitude dimensions do not match.');
end
% Define the UTM zone for your area.
utm_zone = 32;
% Step 2: Transform Coordinates using the built-in 'deg2utm' function
[utm_x, utm_y, utm_zone] = deg2utm(measurement_lat, measurement_lon);
% Define the pixel size and create the grid
pixel_size = 20; % Adjust as needed
x_grid = min(utm_x):pixel_size:max(utm_x);
y_grid = min(utm_y):pixel_size:max(utm_y);
% Step 3: Calculate average RSRP for each pixel
num_pixels_x = numel(x_grid) - 1;
num_pixels_y = numel(y_grid) - 1;
average_rsrp = zeros(num_pixels_y, num_pixels_x); % Initialize the grid.
for i = 1:num_pixels_x
for j = 1:num_pixels_y
% Define the current pixel polygon.
polygon_x = [x_grid(i), x_grid(i + 1), x_grid(i + 1), x_grid(i)];
polygon_y = [y_grid(j), y_grid(j), y_grid(j + 1), y_grid(j + 1)];
% Check if measurements fall within the current pixel.
in_polygon = inpolygon(utm_x, utm_y, polygon_x, polygon_y);
% Calculate average RSRP for the measurements within the polygon.
if any(in_polygon)
rsrp_values_in_polygon = rsrp(in_polygon); % Replace with your RSRP data.
% Convert dBm to watts, compute average, and convert back to dBm.
rsrp_watts = 10 .^ (rsrp_values_in_polygon / 10);
average_rsrp(j, i) = 10 * log10(mean(rsrp_watts));
end
end
end
% Exclude cells with 0 value from the heatmap
average_rsrp(average_rsrp == 0) = NaN;
% Define the color for NaN values (white)
nanColor = [1, 1, 1]; % RGB color for white
% Plot the heatmap of average RSRP with NaN values represented as white
colormap('hot'); % Use the 'hot' colormap for heat colors
heatmap(x_grid(1:end-1), y_grid(1:end-1), average_rsrp, ...
'MissingDataColor', nanColor); % Set the MissingDataColor property
colorbar;
xlabel('UTM X');
ylabel('UTM Y');
title('Average RSRP Heatmap (Excluding 0 Values)');
% updated code

请先登录,再进行评论。

采纳的回答

Dyuman Joshi
Dyuman Joshi 2023-9-30
When using heatmap, colormap has to be specified in the call. See below -
% Load your data
data = readmatrix('subtowersutm.xlsx');
% Extract latitude, longitude, and RSRP values.
measurement_lat = data(:, 1);
measurement_lon = data(:, 2);
rsrp = data(:, 11); % Adjust the column index for RSRP data.
% Check if the dimensions of Lat and Lon match
if size(measurement_lat) ~= size(measurement_lon)
error('Latitude and Longitude dimensions do not match.');
end
% Define the UTM zone for your area.
utm_zone = 32;
% Step 2: Transform Coordinates using the built-in 'deg2utm' function
[utm_x, utm_y, utm_zone] = deg2utm(measurement_lat, measurement_lon);
% Define the pixel size and create the grid
pixel_size = 20; % Adjust as needed
x_grid = min(utm_x):pixel_size:max(utm_x);
y_grid = min(utm_y):pixel_size:max(utm_y);
% Step 3: Calculate average RSRP for each pixel
num_pixels_x = numel(x_grid) - 1;
num_pixels_y = numel(y_grid) - 1;
average_rsrp = zeros(num_pixels_y, num_pixels_x); % Initialize the grid.
for i = 1:num_pixels_x
for j = 1:num_pixels_y
% Define the current pixel polygon.
polygon_x = [x_grid(i), x_grid(i + 1), x_grid(i + 1), x_grid(i)];
polygon_y = [y_grid(j), y_grid(j), y_grid(j + 1), y_grid(j + 1)];
% Check if measurements fall within the current pixel.
in_polygon = inpolygon(utm_x, utm_y, polygon_x, polygon_y);
% Calculate average RSRP for the measurements within the polygon.
if any(in_polygon)
rsrp_values_in_polygon = rsrp(in_polygon); % Replace with your RSRP data.
% Convert dBm to watts, compute average, and convert back to dBm.
rsrp_watts = 10 .^ (rsrp_values_in_polygon / 10);
average_rsrp(j, i) = 10 * log10(mean(rsrp_watts));
end
end
end
% Exclude cells with 0 value from the heatmap
average_rsrp(average_rsrp == 0) = NaN;
% Define the color for NaN values (white)
nanColor = [1, 1, 1]; % RGB color for white
Colormap specified inside the heatmap() call.
% Plot the heatmap of average RSRP with NaN values represented as white
% Set the MissingDataColor property and the colormap
heatmap(x_grid(1:end-1), y_grid(1:end-1), average_rsrp, ...
'MissingDataColor', nanColor, Colormap=hot);
%% ^^^^^^^^^^^^
colorbar;
xlabel('UTM X');
ylabel('UTM Y');
title('Average RSRP Heatmap (Excluding 0 Values)');
  3 个评论
Dyuman Joshi
Dyuman Joshi 2023-9-30
Which map are you trying to plot? Could you attach the code for it?
Sangesh Pv
Sangesh Pv 2023-9-30
% Create a web map using the Mapping Toolbox
webmap;
% Display the map using a web map service (you may need an internet connection)
basemap = wmsfind('nasa', 'SearchField', 'serverurl');
wmslayer = wmsinfo(basemap(1).ServerURL);
layers = wmslayer(1).LayerName;
addWebMap(webmap, layers);
% I tried with this code but it gives as 2 seperate output i dont think so it works, do you think it will be better to convert this utm coordinates back to lat lon so that geoscatter or geoshow command can be used ?
% I just need it to be on top of the streets which the data has been taken with and not a white background in the grided view

请先登录,再进行评论。

更多回答(0 个)

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by