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])
  1 件のコメント
han han
han han 2020 年 7 月 2 日
it works, thank you so much!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by