|
function multiplePlot()<BR>% 可编辑框、弹出框、列表框、按键示例<BR>% 目的:制作能绘制任意图形的交互界面.包括:可编辑文本框、弹出框、列表框.<BR>% 实现关键为如何使得编辑框允许输入多行指令<BR>figure;<BR>global hEdit hPop hList<BR>set(gcf,'menubar','none');<BR>set(gcf,'unit','normalized','position',[.1,.4,.85,.35]);<BR>set(gcf,'defaultuicontrolunits','normalized');<BR>set(gcf,'defaultuicontrolfontsize',11);<BR>set(gcf,'defaultuicontrolfontname','隶书');<BR>set(gcf,'defaultuicontrolhorizontal','left');<BR>str='通过多行指令绘图的交互界面';<BR>set(gcf,'name',str,'numbertitle','off');<BR>hAxes=axes('position',[.05,.15,.45,.7],'visible','off');<BR>uicontrol(gcf,'style','text',...<BR> 'position',[.52,.87,.26,.1],...<BR> 'string','绘图指令输入框');<BR>hEdit=uicontrol(gcf,'style','edit',...<BR> 'position',[.52,.05,.26,.8],...<BR> 'max',2);<BR>hPop=uicontrol(gcf,'style','popup',...<BR> 'position',[.8,.73,.18,.12],...<BR> 'string','spring|summer|autumn|winter');<BR>hList=uicontrol(gcf,'style','list',...<BR> 'position',[.8,.23,.18,.37],...<BR> 'string','Grid on|Box on|Hidden off|Axis off',...<BR> 'max',2);<BR>hPush=uicontrol(gcf,'style','push',...<BR> 'position',[.8,.05,.18,.15],'string','Apply');<BR>% set(hEdit,'callback','calledit(hEdit,hPop,hList)');<BR>% set(hPop,'callback','calledit(hEdit,hPop,hList)');<BR>% set(hPush,'callback','calledit(hEdit,hPop,hList)');<BR>set(hEdit,'callback','calledit');<BR>set(hPop,'callback','calledit');<BR>set(hPush,'callback','calledit');<BR>=============================================================<BR>%另外写一个函数calledit做回调<BR>function calledit<BR>global hEdit hPop hList<BR>ct=get(hEdit,'string'); % 获得输入的字符串函数<BR>vPop=get(hPop,'value'); % 获得选项的位置标识<BR>vList=get(hList,'value'); % 获得选项位置向量<BR>if ~isempty(ct) % 当可编辑框为非空时执行如下指令<BR> eval(ct'); % 运行从编辑文本框送来的指令<BR> popstr={'spring','summer','autumn','winter'}; % 弹出色图框矩阵<BR> liststr={'grid on','box on','hidden off','axis off'};<BR> invstr={'grid off','box off','hidden on','axis on'};<BR> colormap(eval(popstr{vPop}));<BR> vv=zeros(1,4);<BR> vv(vList)=1;<BR> for k=1:4<BR> if vv(k);<BR> eval(liststr{k});<BR> else<BR> eval(invstr{k});<BR> end<BR> end<BR>end |
|