Filter löschen
Filter löschen

how can i use utm2degfunchtion

6 Ansichten (letzte 30 Tage)
Sangesh Pv
Sangesh Pv am 12 Okt. 2023
Kommentiert: Sangesh Pv am 17 Okt. 2023
i am trying to convert the utm coordinates back to degree but i cant figure out. i get multiple errors when i use the function. i need to add this function
[Lat,Lon] = utm2deg(utm_x,utm_y,utm_zone) in the end so that the utm coordinates can be converted back to deg before plotting in the map
% 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 = 10; % 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
% Set the MissingDataColor property and the colormap
heatmap(x_grid(1:end-1), y_grid(1:end-1), average_rsrp, ...
'MissingDataColor', nanColor, Colormap=parula);
colorbar;
xlabel('UTM X');
ylabel('UTM Y');
title('Average RSRP Heatmap (Excluding 0 Values)');
  1 Kommentar
Steven Lord
Steven Lord am 13 Okt. 2023
Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Gyan Vaibhav
Gyan Vaibhav am 17 Okt. 2023
Hi Sangesh, 
To convert UTM coordinates back to degrees, you can add the “utm2deg” function to your code. Here's how you can modify your code to include the “utm2deg” function:
% 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);
% Step 3: Convert UTM coordinates back to degrees using the 'utm2deg' function
[Lat, Lon] = utm2deg(utm_x, utm_y, utm_zone);
% Define the pixel size and create the grid
pixel_size = 10; % Adjust as needed
x_grid = min(utm_x):pixel_size:max(utm_x);
y_grid = min(utm_y):pixel_size:max(utm_y);
% Step 4: 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
heatmap(x_grid(1:end-1), y_grid(1:end-1), average_rsrp, ...
'MissingDataColor', nanColor, 'Colormap', parula);
colorbar;
xlabel('UTM X');
ylabel('UTM Y');
title('Average RSRP Heatmap (Excluding 0 Values)');
% Function to convert UTM coordinates to degrees
function [Lat, Lon] = utm2deg(utm_x, utm_y, utm_zone)
% Implement the conversion logic here
% ...
end
I hope this helps to resolve the issue regarding usage of "utm2deg" function.
Thanks
  1 Kommentar
Sangesh Pv
Sangesh Pv am 17 Okt. 2023
i need to implement in a way that the utm coordintes be converted to degrees so that the heatmap will be produced on top of a map.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by