
图 11.6-1

图 11.6.2-1 待制作的用户界面

图 11.6.2.1-1 属性编辑工具界面
【例 11.6.2.2-1 】整个用户界面的几何布局:“轴”、控件种类、相对位置及大致尺寸。本例演示:( A )设计工具控制面板上“新对象模块区”的图标的使用;( B )几何布局时不必太多考虑各对象的精细位置和大小。

图 11.6.2.2-1 “第二道工序” 构成控件布局的界面
过程中,可能还要适当调整对象几何尺寸,使字符表现清晰醒目。
直接、简单的 MATLAB 语句。 
图 11.6.2.4-1 用户菜单编辑器界面

图 11.6.2.5-1
(1)弹出框的回调函数 Mycolormap.m
[Mycolormap.m]
function Mycolormap
popstr={ 'spring' , 'summer' , 'autumn' , 'winter' }; % 弹出框色图矩阵
vpop=get(findobj(gcf, 'Tag' , 'PopupMenu1' ), 'value' ); % 获得选项的位置标识
colormap(eval(popstr{vpop})) % 采用弹出框所选色图
(2)列表框和“ Apply ”按键配合的回调函数 Myapply.m
[Myapply.m]
function Myapply
vlist=get(findobj(gcf, 'Tag' , 'Listbox1' ), 'value' ); % 获得选项位置向量
liststr={ 'grid on' , 'box on' , 'hidden off' , 'axis off' }; % 列表框选项内容
invstr={ 'grid off' , 'box off' , 'hidden on' , 'axis on' }; % 列表框的逆指令
vv=zeros(1,4);vv(vlist)=1;
for k=1:4
if vv(k);eval(liststr{k}); else eval(invstr{k}); end % 按列表选项影响图形
end
(3)动态编辑框的回调函数 Myedit.m
[Myedit.m]
function Myedit
ct=get(findobj(gcf, 'Tag' , 'EditText1' ), 'string' );
eval(ct')
11.6.2.8 为读者提供的配套文件和数据
(1)机器自动生成的主控文件
[Mygui1.m]
function fig = Mygui1()
% This is the machine-generated representation of a Handle Graphics object
% and its children. Note that handle values may change when these objects
% are re-created. This may cause problems with any callbacks written to
% depend on the value of the handle at the time the object was saved.
% This problem is solved by saving the output as a FIG-file.%
% To reopen this object, just type the name of the M-file at the MATLAB
% prompt. The M-file and its associated MAT-file must be on your path.%
% NOTE: certain newer features in MATLAB may not have been saved in this
% M-file due to limitations of this format, which has been superseded by
% FIG-files. Figures which have been annotated using the plot editor tools
% are incompatible with the M-file/MAT-file format, and should be saved as
% FIG-files.
load Mygui1
h0 = figure( 'Units' , 'normalized' , ...
'Color' ,[0.8553876799929505 0.8553876799929505 0.8553876799929505], ...
'Colormap' ,mat0, ...
'FileName' , 'F:\99\m5\Mygui1.m' , ...
'MenuBar' , 'none' , ...
'Name' , 'GUI 工具设计的界面 ' , ...
'PaperPosition' ,[18 180 575.9999999999999 432], ...
'PaperUnits' , 'points' , ...
'Position' ,[0.1484375 0.5291666666666667 0.8 0.35], ...
'Tag' , 'Fig1' , ...
'ToolBar' , 'none' );
h1 = uimenu( 'Parent' ,h0, ...
'Label' , 'Zoom' , ...
'Tag' , 'M_Z' );
h2 = uimenu( 'Parent' ,h1, ...
'Callback' , 'zoom on' , ...
'Label' , 'On' , ...
'Tag' , 'M_Zon' );
h2 = uimenu( 'Parent' ,h1, ...
'Callback' , 'zoom off' , ...
'Label' , 'Off' , ...
'Tag' , 'M_Zoff' );
h1 = uicontrol( 'Parent' ,h0, ...
'Units' , 'normalized' , ...
'BackgroundColor' ,[0.7529411764706 0.7529411764706 0.7529411764706], ...
'Callback' , 'Mycolormap' , ...
'ListboxTop' ,0, ...
'Position' ,[0.80859375 0.773809523809524 0.16 0.130952380952381], ...
'String' ,[ 'spring ' ; 'summer ' ; 'autumn ' ; 'winter ' ], ...
'Style' , 'popupmenu' , ...
'Tag' , 'PopupMenu1' , ...
'Value' ,1);
h1 = uicontrol( 'Parent' ,h0, ...
'Units' , 'normalized' , ...
'BackgroundColor' ,[1 1 1], ...
'Max' ,2, ...
'Position' ,[0.80859375 0.327380952380952 0.16 0.398809523809524], ...
'String' ,[ 'grid on ' ; 'box on ' ; 'hidden off' ; 'axis off ' ], ...
'Style' , 'listbox' , ...
'Tag' , 'Listbox1' , ...
'Value' ,1);
h1 = uicontrol( 'Parent' ,h0, ...
'Units' , 'normalized' , ...
'BackgroundColor' ,[.752941176470588 .752941176470588 .752941176470588], ...
'Callback' , 'Myapply' , ...
'ListboxTop' ,0, ...
'Position' ,[0.80859375 0.12 0.16 0.15], ...
'String' , 'apply' , ...
'Tag' , 'Pushbutton1' );
h1 = uicontrol( 'Parent' ,h0, ...
'Units' , 'normalized' , ...
'BackgroundColor' ,[1 1 1], ...
'Callback' , 'Myedit' , ...
'FontName' , 'Times New Roman' , ...
'FontSize' ,10, ...
'HorizontalAlignment' , 'left' , ...
'ListboxTop' ,0, ...
'Max' ,2, ...
'Position' ,[.55078125 .3273809523809524 .232421875 .4523809523809523], ...
'Style' , 'edit' , ...
'Tag' , 'EditText1' );
h1 = axes( 'Parent' ,h0, ...
'CameraUpVector' ,[0 1 0], ...
'CameraUpVectorMode' , 'manual' , ...
'Color' ,[1 1 1], ...
'ColorOrder' ,mat1, ...
'Position' ,[0.05 0.15 0.45 0.65], ...
'Tag' , 'Axes1' , ...
'XColor' ,[0 0 0], ...
'YColor' ,[0 0 0], ...
'ZColor' ,[0 0 0]);
h2 = text( 'Parent' ,h1, ...
'Color' ,[0 0 0], ...
'HandleVisibility' , 'off' , ...
'HorizontalAlignment' , 'center' , ...
'Position' ,[0.4978165938864628 -0.2222222222222221 9.160254037844386], ...
'Tag' , 'Axes1Text4' , ...
'VerticalAlignment' , 'cap' );
set(get(h2, 'Parent' ), 'XLabel' ,h2);
h2 = text( 'Parent' ,h1, ...
'Color' ,[0 0 0], ...
'HandleVisibility' , 'off' , ...
'HorizontalAlignment' , 'center' , ...
'Position' ,[-0.1353711790393013 0.4907407407407408 9.160254037844386], ...
'Rotation' ,90, ...
'Tag' , 'Axes1Text3' , ...
'VerticalAlignment' , 'baseline' );
set(get(h2, 'Parent' ), 'YLabel' ,h2);
h2 = text( 'Parent' ,h1, ...
'Color' ,[0 0 0], ...
'HandleVisibility' , 'off' , ...
'HorizontalAlignment' , 'right' , ...
'Position' ,mat2, ...
'Tag' , 'Axes1Text2' , ...
'Visible' , 'off' );
set(get(h2, 'Parent' ), 'ZLabel' ,h2);
h2 = text( 'Parent' ,h1, ...
'Color' ,[0 0 0], ...
'HandleVisibility' , 'off' , ...
'HorizontalAlignment' , 'center' , ...
'Position' ,[0.4978165938864628 1.064814814814815 9.160254037844386], ...
'Tag' , 'Axes1Text1' , ...
'VerticalAlignment' , 'bottom' );
set(get(h2, 'Parent' ), 'Title' ,h2);
h1 = uicontrol( 'Parent' ,h0, ...
'Units' , 'normalized' , ...
'FontName' , ' 隶书 ' , ...
'FontSize' ,13, ...
'HorizontalAlignment' , 'left' , ...
'ListboxTop' ,0, ...
'Position' ,[0.55 0.8 0.2 0.12], ...
'String' , ' 输入绘图指令 ' , ...
'Style' , 'text' , ...
'Tag' , 'StaticText1' );
h1 = uicontrol( 'Parent' ,h0, ...
'Units' , 'normalized' , ...
'BackgroundColor' ,[.752941176470588 .752941176470588 .752941176470588], ...
'Callback' , 'close(gcbf)' , ...
'ListboxTop' ,0, ...
'Position' ,[0.5869921874999999 0.12 0.16 0.15], ...
'String' , 'Close' , ...
'Tag' , 'Pushbutton2' );
if nargout > 0, fig = h0; end
(2)配套数据文件
[Myguizzy.m]
function Myguizzy
% 假如 Mygui1.m 所在目录不是 d:\matbook5\mdisk ,那么第 <10> 条就应做相应的改变。
% 一定要保证本函数生成的 Mygui1.mat 与 Mygui1.m 在同一目录。
mat0=jet(64);
mat1=[ 0 0 1.0000
0 0.5000 0
1.0000 0 0
0 0.7500 0.7500
0.7500 0 0.7500
0.7500 0.7500 0
0.2500 0.2500 0.2500];
mat2=[-0.1179 1.3056 9.1603];
save d:\matbook5\mdisk\Mygui1 %<10>
(3)如何利用本节所提供的文件产生图 11.6.2-1 所示的界面
1、把本节提供的 Mygui1.m , Myguizzy.m , Mycolormap.m , Myapply.m , Myedit.m 五个文件放在 MATLAB 的搜索路径上。
2、先运行 Myguizzy.m ,创建数据文件 Mygui1.mat 。
3、运行 Mygui1.m ,就可得到符合要求的界面。

您知道全球最小的机器人到底有多小呢。这么小的机器人到底有什么样的法宝呢。中国台湾...

前言 线切割加工通过电极丝与导电工件之间放电腐蚀成型来完成工件加工,由于是非接触加...

唯一要说明的是因为考虑到下身的中间的两条曲线是向里凹而两端是向外凸的,所以我在拐...

——记中国石油天然气第六建设公司劳海峰同志 劳海峰出生于1963年,中共党员,高级焊...

【本文摘要】他胸襟开阔,收揽天下英才,将众多能人志士汇聚旗下,他挥动资本巨手打造...