|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
如题:程序如下
1 y. o1 }5 K8 u" Y }5 c ]: Qfunction exm1151_1( )
& K) b$ x' R0 i6 y) U5 y1 kglobal hedit hpop hlist
: R2 N# O0 ^ s8 M- |3 t mclf reset % <1>
1 l- c; O7 ?, X5 I& ^5 aset(gcf,'unit','normalized','position',[0.1,0.4,0.85,0.35]);%设置图形窗大小
8 j: ?) ^4 y+ m- b- z. @7 C# Uset(gcf,'defaultuicontrolunits','normalized');5 d/ j" n0 [& I. ~$ C8 [
set(gcf,'defaultuicontrolfontsize',11);2 e4 |8 V5 v! G$ T* h
set(gcf,'defaultuicontrolfontname','隶书');; Z& z! A& n8 N$ ~$ g) C7 S
set(gcf,'defaultuicontrolhorizontal','left');
2 N3 N/ W g6 K- K: N$ hset(gcf,'menubar','none'); %删除图形窗工具条$ e: j2 y# L5 G' y0 ^3 ?. z% [
str='通过多行指令绘图的交互界面';! y, D- K P$ W6 b V2 R
set(gcf,'name',str,'numbertitle','off'); %书写图形窗名6 B8 U. k; V$ ^* [& @* i/ G) w
h_axes=axes('position',[0.05,0.15,0.45,0.70],'visible','off');%定义轴位框位置 # _% \! V' \9 z, b
uicontrol(gcf,'Style','text',... %制作静态文本框( X; P- P$ Y/ q9 k+ C
'position',[0.52,0.87,0.26,0.1],...; F& H( R Q* X5 i# q$ E4 M& E# F
'String','绘图指令输入框');
! g4 X2 A/ P' Z( o) b1 X0 l( d) y/ Jhedit=uicontrol(gcf,'Style','edit',... %制作可编辑文本框 <14>$ C+ E1 W9 f! _! F- X$ X5 a
'position',[0.52,0.05,0.26,0.8],...
) ]& H! C, w" N8 F1 M 'Max',2); %取2,使Max-Min>1,而允许多行输入 <16>
' J6 Q/ L; Y& j1 {6 i8 jhpop=uicontrol(gcf,'style','popup',... %制作弹出菜单 <17> J: C, @8 L, E1 Z3 q/ O/ x% ^
'position',[0.8,0.73,0.18,0.12],...
1 s5 s# l2 o2 O! L 'string','spring|summer|autumn|winter');%设置弹出框中选项名 <19>: R6 t; m) z! m- q) d
hlist=uicontrol(gcf,'Style','list',... %制作列表框 <20>! V7 B, x8 c& r7 W( e0 x' g8 K/ t
'position',[0.8,0.23,0.18,0.37],...
4 p4 M2 T! G n# f) J2 d( I. ` 'string','Grid on|Box on|Hidden off|Axis off',...%设置列表框中选项名 <22>
) q: `) e) N2 h 'Max',2); %取2,使Max-Min>1,而允许多项选择 <23>
' g3 b2 J" F9 n7 c8 l9 T) h/ Yhpush=uicontrol(gcf,'Style','push',... %制作与列表框配用的按键 <24>' ?8 X1 b( d) I7 ]4 H3 K
'position',[0.8,0.05,0.18,0.15],'string','Apply');% <25>
% o' q! W7 V5 e& a. N; Uset(hedit,'callback','calledit1'); %编辑框输入引起回调 <26>
& h9 b+ C7 P3 k+ G$ ^! kset(hpop,'callback','calledit1'); %弹出框选择引起回调 <27>
4 E) p# r5 g( K! v, p% Mset(hpush,'callback','calledit1'); %按键引起的回调 <28>3 b) Y1 f5 [! P4 r0 w/ t0 g
function calledit1( )/ B2 f8 B; K T1 i* }; }
global hedit hpop hlist
' W9 i4 R! z. K. vct=get(hedit,'string'); %获得输入的字符串函数 <2>7 B8 s' v- l2 n/ _" P! B& o
vpop=get(hpop,'value'); %获得选项的位置标识 <3>9 I5 e+ A4 S, t" m, l+ e& A, z
vlist=get(hlist,'value'); %获得选项位置向量 <4>$ e2 U. U* _3 c( _3 U) f( ^
if ~isempty(ct) %可编辑框输入非空时 <5>& P% D9 c h, v9 Q
eval(ct') %运行从编辑文本框送入的指令 <6>
) f. v( B$ i: u" d8 ]8 t popstr={'spring','summer','autumn','winter'}; %弹出框色图矩阵 <7>
4 C+ Y2 \) ?4 w* V7 ] liststr={'grid on','box on','hidden off','axis off'};%列表框选项内容 <8> ( O( ?4 {2 \& q, _. c% l9 @
invstr={'grid off','box off','hidden on','axis on'};%列表框的逆指令 <9>
* ~+ D: [6 ? O3 I- c! R colormap(eval(popstr{vpop})) %采用弹出框所选色图 <10>
2 `) a4 z' l9 k" v; y$ z7 h vv=zeros(1,4);vv(vlist)=1; ' r# M7 Z. l- l
for k=1:4# c$ A' ]. o$ k# ?, L' y
if vv(k);eval(liststr{k});else eval(invstr{k});end %按列表选项影响图形! N& H5 [; n& u+ ~- a
end
( z* o4 p0 h I( t2 r- wend
. t A2 A0 h3 `+ s5 g4 n8 P《掌握和精通matlab之gui》的代码,
; E9 l9 x2 o- n+ F7 }6 ]2 S! o; ]可是按照此书上的例子运行出现:Undefined function or variable 'calledit1'. Error while evaluating UIControl Callback0 q2 H3 J8 I# M5 r( ^! X
- ~: V! r: ?- S3 W6 F
书上的例子出的图
' I5 U* C0 _) R3 G) j' {请教大神,非常感谢!7 A* I+ h% S$ |2 N9 b$ ]
3 l# ~; L* a8 R) k& O0 ?/ T& n9 m: a0 G+ n' I. r
|
|