Filter löschen
Filter löschen

How to add map to an output

1 Ansicht (letzte 30 Tage)
Sangesh Pv
Sangesh Pv am 29 Sep. 2023
Kommentiert: Sangesh Pv am 30 Sep. 2023
I am trying to add the output to a map but i can't figure out how to add it.
  7 Kommentare
Sangesh Pv
Sangesh Pv am 29 Sep. 2023
% 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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Dyuman Joshi
Dyuman Joshi am 30 Sep. 2023
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 Kommentare
Dyuman Joshi
Dyuman Joshi am 30 Sep. 2023
Which map are you trying to plot? Could you attach the code for it?
Sangesh Pv
Sangesh Pv am 30 Sep. 2023
% 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Geographic Plots finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by