필터 지우기
필터 지우기

How to delete the ellipse of the previous state

조회 수: 2 (최근 30일)
han han
han han 2020년 7월 2일
답변: Image Analyst 2020년 7월 2일
I want to implement an input UE ID (edit1) will display an ellipse on axes.
But I want to have only one ellipse on axes.
For example: when I enter UE ID 5 and press pushbutton, and then enter UE ID 6 and press pushbutton, axes only show the ellipse of UE ID 6.
How can I modify it?
function pushbutton2_Callback(hObject, eventdata, handles)
[UELocation] = textread('observe/mdUELocationforGUI2.txt');
InputUEID = get(handles.edit1,'String');
InputUEID = str2double(InputUEID);
InputUEID3 = InputUEID+1;
[Pairlink] = textread('observe/mdPairlinkforGUI2.txt');
Node_ID = Pairlink(InputUEID3,4); %NodeID
Node_ID2 = Node_ID+1;
[UEBeamAngle] = textread('observe/mdUEHBeamAngleforGUI2.txt');
angles_Panel_0 = UEBeamAngle;
[NodeBeam] = textread('observe/mdNodeBeamforGUI2.txt');
Node_beamnumber = NodeBeam(1,3);
[NodeBeamAngle] = textread('observe/mdNodeBeamHAngleGUI2.txt');
angles = NodeBeamAngle + 60;
axes(handles.axes1)
hold on
xUECenter=UELocation(InputUEID3,2);
yUECenter=UELocation(InputUEID3,3);
[Nodelocation] = textread('observe/mdNodeLocationXY_axisforGUI2.txt');
ROIX = Nodelocation(1,5);
ROIY = Nodelocation(1,6);
axis([0 ROIX 0 ROIY])
a = 25*ROIX/1000; %The length and width of the ellipse
b = 25*ROIX/1000;
r = a;
LineSpec='b';
plot_ellipse(a,b,r,xUECenter,yUECenter,angles_Panel_0,LineSpec)
xNodeCenter=Nodelocation(Node_ID2,2);
yNodeCenter=Nodelocation(Node_ID2,3);
r = a;
LineSpec='k';
plot_ellipse(a,b,r,xNodeCenter,yNodeCenter,angles,LineSpec)
axis equal
function plot_ellipse(a,b,r,xNodeCenter,yNodeCenter,angles,LineSpec) % Draw ellipse function
%write documentation here explaing inputs and usage
hEllipse = imellipse(gca,[-a, -b, 2*a, 2*b]);
xy = hEllipse.getVertices();
delete(hEllipse)
x = xy(:,1);
y = xy(:,2);
xy = [x y];
for k = 1 : length(angles)
theta = angles(k);
rotationArray = [cosd(theta) sind(theta); -sind(theta) cosd(theta)];
rotated_xy = xy * rotationArray;
xCenter = xNodeCenter + (r - 0.25) * cosd(theta);
yCenter = yNodeCenter + (r - 0.25) * sind(theta);
x = rotated_xy(:,1) + xCenter;
y = rotated_xy(:,2) + yCenter;
plot(x, y, LineSpec);
if k == 1
grid on;
hold on;
end
end

채택된 답변

Image Analyst
Image Analyst 2020년 7월 2일
Before you call plot(), call this function:
ClearLinesFromAxes(gca);
Here is the function:
%=====================================================================
% Erases all lines from the image axes "h".
function ClearLinesFromAxes(h)
axesHandlesToChildObjects = findobj(h, 'Type', 'line');
if ~isempty(axesHandlesToChildObjects)
delete(axesHandlesToChildObjects);
end
return; % from ClearLinesFromAxes

추가 답변 (1개)

Voss
Voss 2020년 7월 2일
One way might be to turn hold off before plotting your ellipse(s). If you change this:
axes(handles.axes1)
hold on
to this:
axes(handles.axes1)
hold off
Does that work?

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by