フィルターのクリア

How can i make the output hide and show only when the output when the cursor is placed

1 回表示 (過去 30 日間)
Sangesh Pv
Sangesh Pv 2023 年 10 月 7 日
回答済み: Voss 2023 年 10 月 7 日
This is the code i am working it but i have a problem when i run the output it gives output on top of each point but i want it to be hidden and displayed only when i click that point,how can i make it that way.if you look at the output it will explain much clearer (Too much text)
% 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.
% Initialize a matrix to store the count of values considered
value_count = zeros(num_pixels_y, num_pixels_x);
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));
value_count(j, i) = numel(rsrp_values_in_polygon); % Store the count of values
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
% Create a new figure
fig = figure;
% Plot the heatmap of average RSRP with NaN values represented as white
imagesc(x_grid(1:end-1), y_grid(1:end-1), average_rsrp, 'AlphaData', ~isnan(average_rsrp));
colormap(parula);
colorbar;
xlabel('UTM X');
ylabel('UTM Y');
title('Average RSRP Heatmap (Excluding 0 Values) with Value Count');
% Add text annotations for value count in each plot
for i = 1:num_pixels_x
for j = 1:num_pixels_y
if ~isnan(average_rsrp(j, i))
text(x_grid(i), y_grid(j), sprintf('Count: %d', value_count(j, i)), ...
'HorizontalAlignment', 'center', 'VerticalAlignment', 'middle', 'Color', 'k');
end
end
end

採用された回答

Voss
Voss 2023 年 10 月 7 日
This will toggle the visibility of a text object when you click on its corresponding pixel in the image. All text objects are initially invisible.
% 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.
% Initialize a matrix to store the count of values considered
value_count = zeros(num_pixels_y, num_pixels_x);
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));
value_count(j, i) = numel(rsrp_values_in_polygon); % Store the count of values
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
% Create a new figure
fig = figure;
% Plot the heatmap of average RSRP with NaN values represented as white
img = imagesc(x_grid(1:end-1), y_grid(1:end-1), average_rsrp, 'AlphaData', ~isnan(average_rsrp));
colormap(parula);
colorbar;
xlabel('UTM X');
ylabel('UTM Y');
title('Average RSRP Heatmap (Excluding 0 Values) with Value Count');
% Add text annotations for value count in each plot
t = gobjects(num_pixels_y,num_pixels_x);
for i = 1:num_pixels_x
for j = 1:num_pixels_y
if ~isnan(average_rsrp(j, i))
t(j,i) = text(x_grid(i), y_grid(j), sprintf('Count: %d', value_count(j, i)), ...
'HorizontalAlignment', 'center', 'VerticalAlignment', 'middle', 'Color', 'k', ...
'Visible', 'off', 'HitTest', 'off', 'PickableParts', 'none');
end
end
end
set(img,'ButtonDownFcn',{@bdf_image,t});
function bdf_image(src,evt,t)
[~,xidx] = min(abs(get(src,'XData')-evt.IntersectionPoint(1)));
[~,yidx] = min(abs(get(src,'YData')-evt.IntersectionPoint(2)));
if ishandle(t(yidx,xidx))
if strcmp(t(yidx,xidx).Visible,'off')
t(yidx,xidx).Visible = 'on';
else
t(yidx,xidx).Visible = 'off';
end
end
end

その他の回答 (2 件)

Mann Baidi
Mann Baidi 2023 年 10 月 7 日
Hi Sangesh,
I understand you would like to display the text only when the user click on that specific point,for this you can use the "WindowButtonDownFcn" callback function.You can refer to the below code for using the callback function.
set(fig, 'WindowButtonDownFcn',@clicker);
function clicker(average_rsrp,x_grid,y_grid,value_count,~)
[i,j]= ginput(1);
text(x_grid(j), y_grid(i), sprintf('Count: %d', value_count(j, i)), ...
'HorizontalAlignment', 'center', 'VerticalAlignment', 'middle', 'Color', 'k');
end
I hooe this will resolve your issue.

Walter Roberson
Walter Roberson 2023 年 10 月 7 日
I suggest that you use datacursormode instead -- which is the program equivalent of clicking to enable data tips.

カテゴリ

Help Center および File ExchangeTitle についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by