How to add map to an output (2024)

1 view (last 30 days)

Show older comments

Sangesh Pv on 29 Sep 2023

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output

Commented: Sangesh Pv on 30 Sep 2023

Accepted Answer: Dyuman Joshi

I am trying to add the output to a map but i can't figure out how to add it.

7 Comments

Show 5 older commentsHide 5 older comments

Sangesh Pv on 29 Sep 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2904444

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2904444

Open in MATLAB Online

  • subtowersutm.xlsx

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);

Unrecognized function or variable 'deg2utm'.

% 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

% Step 4: Plot the heatmap of average RSRP

% You can use various plotting functions to visualize the heatmap.

heatmap(x_grid(1:end-1), y_grid(1:end-1), average_rsrp);

colorbar;

xlabel('UTM X');

ylabel('UTM Y');

title('Average RSRP Heatmap');

Dyuman Joshi on 29 Sep 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2904454

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2904454

Open in MATLAB Online

"% Step 2: Transform Coordinates using the built-in 'deg2utm' function"

which -all deg2utm

'deg2utm' not found.

There is no built-in function named deg2utm, as you can see above.

Which function were you trying to use?

Sangesh Pv on 29 Sep 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2904669

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2904669

Edited: Voss on 29 Sep 2023

i used this script to use deg 2 utm

[Voss EDIT: code from File Exchange removed. Link is: https://www.mathworks.com/matlabcentral/fileexchange/10915-deg2utm]

Dyuman Joshi on 29 Sep 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2904739

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2904739

Open in MATLAB Online

  • subtowersutm.xlsx

What's the problem here?

What do you want to obtain? Can you provide an example as to what the expected output should be?

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

% Step 4: Plot the heatmap of average RSRP

% You can use various plotting functions to visualize the heatmap.

heatmap(x_grid(1:end-1), y_grid(1:end-1), average_rsrp);

colorbar;

xlabel('UTM X');

ylabel('UTM Y');

title('Average RSRP Heatmap');

How to add map to an output (6)

Sangesh Pv on 29 Sep 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2904774

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2904774

  • Need.png
  • needed.png

i need the output to be colored like the picture need.png below when I mention the color below in the code it doesn't change and I need it on top of a Map like the picture needed.png

Walter Roberson on 29 Sep 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2904779

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2904779

deg2utm appears to be from https://www.mathworks.com/matlabcentral/fileexchange/10915-deg2utm

Sangesh Pv on 29 Sep 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2904784

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2904784

Open in MATLAB Online

% 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

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Dyuman Joshi on 30 Sep 2023

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#answer_1322629

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#answer_1322629

Open in MATLAB Online

  • deg2utm.m
  • subtowersutm.xlsx

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)');

How to add map to an output (11)

3 Comments

Show 1 older commentHide 1 older comment

Sangesh Pv on 30 Sep 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2905449

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2905449

perfect and how can i get this output on an map ?

Dyuman Joshi on 30 Sep 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2905454

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2905454

Which map are you trying to plot? Could you attach the code for it?

Sangesh Pv on 30 Sep 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2905474

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2027249-how-to-add-map-to-an-output#comment_2905474

Open in MATLAB Online

% 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

Sign in to comment.

More Answers (0)

Sign in to answer this question.

See Also

Categories

MATLABGraphics2-D and 3-D PlotsGeographic Plots

Find more on Geographic Plots in Help Center and File Exchange

Tags

  • maps

Products

  • MATLAB

Release

R2023b

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


How to add map to an output (15)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

How to add map to an output (2024)
Top Articles
Latest Posts
Article information

Author: Ms. Lucile Johns

Last Updated:

Views: 6489

Rating: 4 / 5 (61 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Ms. Lucile Johns

Birthday: 1999-11-16

Address: Suite 237 56046 Walsh Coves, West Enid, VT 46557

Phone: +59115435987187

Job: Education Supervisor

Hobby: Genealogy, Stone skipping, Skydiving, Nordic skating, Couponing, Coloring, Gardening

Introduction: My name is Ms. Lucile Johns, I am a successful, friendly, friendly, homely, adventurous, handsome, delightful person who loves writing and wants to share my knowledge and understanding with you.