필터 지우기
필터 지우기

How to add map to an output

조회 수: 1 (최근 30일)
Sangesh Pv
Sangesh Pv 2023년 9월 29일
댓글: Sangesh Pv 2023년 9월 30일
I am trying to add the output to a map but i can't figure out how to add it.
  댓글 수: 7
Walter Roberson
Walter Roberson 2023년 9월 29일
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개)

카테고리

Help CenterFile Exchange에서 Geographic Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by