大家好,又见面了,我是你们的朋友全栈君。
转载请注明来自:黄朝辉的博客
这里我们来实现一个加法器,功能比较简单,主要用于了解matlab中的代码是如何与控件进行交互。
在命令行窗口中输入:
>> guide
直接“确定”即可。 将需要的控件从左边托至中间的编辑窗口,如下图。
将按钮的“Tag”修改为“compute_pushbutton”。
在“计算”按钮上,右键–》查看回调–》CallBack。
在function compute_pushbutton_Callback(hObject, eventdata, handles)
后加入以下内容:
% hObject handle to compute_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a1=str2double(get(handles.edit1,'String'));
a2=str2double(get(handles.edit2,'String'));
set(handles.text4,'String',num2str(a1+a2));
注意:
这里需要 第一个编辑框的Tag为edit1
, 第二个编辑框的Tag为edit2
,如果你的不是,改为你的编辑框的Tag即可。
text4
为你需要显示计算结果的控件的Tag。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/135800.html原文链接:https://javaforall.cn
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有