|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
/ n' d/ |$ s# L前言:
+ R" h8 ^8 `( |; o当然了这个太简单了,新手可以借鉴一下,举一反三的话还可以添加一些功能或者简洁一些。比如下拉框啊之类的( i& a' _- N) z- A, P
而且呢,这个你弄明白了,所有运算有关的,输入输出有关的,都大致相同。3 I$ \+ C. K! }
- v9 L$ o, Z# K实现过程
' x1 j; V7 L3 j+ q2 s( k- B先是一个个的添加。漫长的过程~~
* o. d2 o/ k. H. {下面图错了,最右边应该添加text而不是edit,我当时截图的时候没改过来。。4 L0 J1 J8 i( v5 ^. l# k
+ F6 V: @5 T% }2 w7 z/ ~# E
9 f/ ^0 M* T" e9 c
" K8 x @& B+ Z8 C* A
然后呢,我们从左到右从上到下依次编号edit然后编text~~9 V( {3 N2 B$ v" S' q* ]. p1 k
/ H2 a) R3 ^: [8 R3 }
, S, h- J& i E# j+ F) M8 G/ {/ V5 ]! a
然后找到那八个可编辑文本的回调函数' e7 h# ?6 ~' H% T( W% Y
1 X( ` `) l# `& c7 z3 t$ \
输入代码:
& f/ T- f) w p/ d6 C! a1 u9 d5 w3 e/ K9 b2 y0 [2 g4 J0 {
- a=str2num(get(hObject,'String'));%将字符串转换为数字
- if isempty(a)%如果为空则设置为默认值
- set(hObject,'String','0');
- end;
- guidata(hObject,handles);%更新
* g0 p0 b' F: G % e- w; z+ j8 i# y1 l
9 Y; M1 x- X" ~3 G/ {) A再找到按钮的回调函数
" P, ~1 D+ H- \ e0 k$ G1 O O
3 b P2 ?% w/ A( A# A输入代码:0 Q! Y2 b7 [3 ~/ [1 S
' o$ e! |) t( h& E: n- a=get(handles.edit1,'String');
- b=get(handles.edit2,'String');
- c=str2num(a)+str2num(b);
- set(handles.text3,'String',num2str(c));
- guidata(hObject,handles);
- a=get(handles.edit4,'String');
- b=get(handles.edit5,'String');
- c=str2num(a)-str2num(b);
- set(handles.text6,'String',num2str(c));
- guidata(hObject,handles);
- a=get(handles.edit7,'String');
- b=get(handles.edit8,'String');
- c=str2num(a)*str2num(b);
- set(handles.text9,'String',num2str(c));
- guidata(hObject,handles);
- a=get(handles.edit10,'String');
- b=get(handles.edit11,'String');
- if str2num(b)==0
- c=0;
- else
- c=str2num(a)/str2num(b);
- end;
- set(handles.text12,'String',num2str(c));
- guidata(hObject,handles);
5 @; v# a0 j+ N9 u& ?2 f. w. v @
1 Q2 b! H/ z H2 i* O$ E
& e; u% ?0 I& N; C' c最后ok
9 q' a3 M r1 x/ A效果:(我敢说,现在计算器没有这种批处理的~~)
+ M4 Z% j1 e- g4 ], u8 M$ S# c3 B* v1 B9 D/ o3 D
, l. b, L. x/ t" n6 d3 B* v( W8 z( t0 U+ }' O Z. a7 a P8 i L
, S! q( b* _/ O0 M. V1 @9 _9 | |
|