How to delete the text of the previous state

조회 수: 4 (최근 30일)
han han
han han 2020년 7월 2일
편집: Walter Roberson 2020년 7월 2일
I want to implement an input UE ID (edit1) will display text on axes.
But I want to have only one text on axes.
For example: I entered UE ID 5 and pressed pushbutton, and then entered UE ID 6 and pressed pushbutton. When axes only displayed the text of UE ID 6.
function varargout = untitled(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before untitled is made visible.
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = untitled_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function pushbutton2_Callback(hObject, eventdata, handles)
[UElocation] = textread('observe/mdUELocationforGUI2.txt');
InputUEID = get(handles.edit1,'String');
InputUEID2 = str2double(InputUEID);
InputUEID3 = InputUEID2+1;
axes(handles.axes1)
c = string(InputUEID);
x3 = text(UElocation(InputUEID3,2), UElocation(InputUEID3,3), c,'FontSize',16);
axis([0 120 0 120])
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

채택된 답변

Walter Roberson
Walter Roberson 2020년 7월 2일
편집: Walter Roberson 2020년 7월 2일
function pushbutton2_Callback(hObject, eventdata, handles)
[UElocation] = textread('observe/mdUELocationforGUI2.txt');
InputUEID = get(handles.edit1,'String');
InputUEID2 = str2double(InputUEID);
InputUEID3 = InputUEID2+1;
ax = handles.axes1;
delete(findobj(ax.Children, 'flat', 'type','text')); %delete previous text if any
c = string(InputUEID);
x3 = text(ax, UElocation(InputUEID3,2), UElocation(InputUEID3,3), c,'FontSize',16);
axis(ax, [0 120 0 120])

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by