1. 画出GUI 界面如下
Edit Text的 Tag 是 edit__data
Save Data 按钮的Tag是 pushbutton__save
2. 在pushbutton__save 的Callback函数里输入最下面两行,这个callback整个代码如下:
function pushbutton__save_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton__save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data1 = str2num(char(get(handles.edit__data, 'String')));
save data.mat data1
3. 保存fig文件以及对应的m文件
4. 运行程序
在框里输入如 数字2
点击save data按钮
则保存变量2至data.mat里了