首页 > 代码库 > Matlab学习----------GUI数据管理
Matlab学习----------GUI数据管理
向gui handles结构体中添加新的字段:
hbtn=uicontrol(‘tag‘,‘mybtn‘,...
‘style‘,‘pushbutton‘,...%普通的按钮
‘callback‘,{@mybtn_Callback,handles},...%回调函数
‘string‘,‘用户自定义的按钮‘,...%按钮上的内容
‘units‘,‘normalized‘,...
‘position‘,[0.45 0.5 0.2 0.1]);
handles.mybtn=hbtn;
handles.text=get(hbtn,‘string‘);
% Update handles structure
guidata(hObject, handles);
结果:
handles =
figure1: 176.0073
pushbutton1: 2.0189
edit1: 177.0073
output: 176.0073
mybtn: 3.0132
text: ‘用户自定义的按钮‘
定义Callback函数
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.mybtn,‘string‘,‘我的文字改变了‘);