20.11M文件例子 精通 MATLAB工具箱含有许多实用函数,它们可以验证本章的许多概念。这些函数的基 本部分已经在二维和三维图形这些章阐述过了。有了前面对句柄图形的讨论,我们现在可以更 彻底地讨论这些函数 最简单的精通 MATLAB工具箱的函数之一提出了一个共同的问题。 MATLAB函数gcf返 回当前图形的句柄。但是,它有一个副作用。如果图形不存在,gcf就创建一个,并返回它的句 柄。如果想寻找一个图形是否存在于头一个位置,要是没有,又不得不创建,怎么办?函数mmgf 正好实现由其内容所描述的工作。 function HF=mmgcf %MMGCF Get Current Figure if it Exists MMGCF returns the handle of the current figure if it exists If no current figure exists, MMGCF returns an empty handle Note that the function gCF is different lt creates a figure and returns its handle if it does not st Copyright (c) 1996 by Prentice-Hall, Inc Hf-get(O, Children); check for figure children if isempty (Hf) return else Hf=get(O, CurrentFigure') d 函数 meget首先检査根对象的子对象的图形是否存在,如至少有一个图形对象时,根对象 的 urrent Figure'属性就返回当前的图形 函数 mmgca为坐标轴对象执行同样的功能,如同在它的M文件内所描述的那样。 function Ha=mmgca MMGCA Get Current Axes if it exists MMGCA returns the handle of the current axes if it exists If no current axes exists, MMGCA returns an empty handle Note that the function gca is diffent lt create a figure and an axes and returns the axes handle if they do not exist. Copyright (c) 1996 by Prentice-Hall, Inc
20.11 M 文件例子 精通 MATLAB 工具箱含有许多实用函数,它们可以验证本章的许多概念。这些函数的基 本部分已经在二维和三维图形这些章阐述过了。有了前面对句柄图形的讨论,我们现在可以更 彻底地讨论这些函数。 最简单的精通 MATLAB 工具箱的函数之一提出了一个共同的问题。MATLAB 函数 gcf 返 回当前图形的句柄。但是,它有一个副作用。如果图形不存在,gcf 就创建一个,并返回它的句 柄。如果想寻找一个图形是否存在于头一个位置,要是没有,又不得不创建,怎么办?函数 mmgcf 正好实现由其内容所描述的工作。 function HF=mmgcf %MMGCF Get Current Figure if it Exists. % MMGCF returns the handle of the current figure if it exists. % If no current figure exists,MMGCF returns an empty handle. % % Note that the function GCF is different.It creates a figure and returns its handle if it does not % exist. % Copyright (c) 1996 by Prentice-Hall,Inc. Hf=get(0, ‘Children’ ); % check for figure children if isempty(Hf) return else Hf=get(0, ‘CurrentFigure’ ); end 函数 mmgcf 首先检查根对象的子对象的图形是否存在,如至少有一个图形对象时,根对象 的 ‘CurrentFigure’ 属性就返回当前的图形。 函数 mmgca 为坐标轴对象执行同样的功能,如同在它的 M 文件内所描述的那样。 function Ha=mmgca %MMGCA Get Current Axes if it exists. % MMGCA returns the handle of the current axes if it exists. % If no current axes exists,MMGCA returns an empty handle. % % Note that the function GCA is diffent.It create a figure and an axes and returns the axes % handle if they do not exist. % Copyright (c) 1996 by Prentice-Hall,Inc
Ha=findobj(o, Type, axes') Ha=get( get(O, Current Figfure'), 'CurrentAxes') 由于函数gco已经表现出当对象不存在时返回空矩阵的行为特性,就不需要函数 mmgco 在精通 MATLAB工具箱中的另一个函数是 mmap,在二维图形那一章里已作过介绍。如 下M文件中所示,它使用 mmgcf作错误检查,与 findobj和get一起删除一个指定的图形。 function mmzap(arg) %MMZAP Delete graphics object using mouse MMZAP waits for a mouse click on an object in a figure window and deletes the object MMZAP or MMZAP text erases text objects MMZAP axes erases axes objects MMZAP line erases line objects MMZAP surf erases surface objects %o MMZAP patch erases patch objects % Clicking on an object other than the selected type or striking a key on the keyboard aborts the command Copyright (c) 1996 by Prentice-Hall, Hf-mmgcf if isempty(Hf), error( No Figure Available. ), end if length( findobj(o, type figure(Hf) bring only figure forword key=waitforbuttonpress; pause untill user takes some action if key key on keyboard pressed return take no acti bject=gco get object selected by buttonpress pe=get(object, Type'); if all(type( 1: 4)=arg( 1: 4))% delete only if Type is correct delete(object)
Ha=findobj(0, ‘Type’ , ‘axes’ ); if isempty(Ha) return else Ha=get(get(0, ‘CurrentFigfure’ ), ‘CurrentAxes’ ); end 由于函数 gco 已经表现出当对象不存在时返回空矩阵的行为特性,就不需要函数 mmgco 了。 在精通 MATLAB 工具箱中的另一个函数是 mmzap,在二维图形那一章里已作过介绍。如 下 M 文件中所示,它使用 mmgcf 作错误检查,与 findobj 和 get 一起删除一个指定的图形。 function mmzap(arg) %MMZAP Delete graphics object using mouse. % MMZAP waits for a mouse click on an object in a figure window and deletes the object. % MMZAP or MMZAP text erases text objects. % MMZAP axes erases axes objects. % MMZAP line erases line objects. % MMZAP surf erases surface objects. % MMZAP patch erases patch objects. % % Clicking on an object other than the selected type or striking a key on the keyboard aborts % the command. % Copyright (c) 1996 by Prentice-Hall,Inc. if nargin<1,arg= ‘text’ ;end Hf=mmgcf; if isempty(Hf),error( ‘No Figure Available.’ ),end if length(findobj(0, ‘Type’ , ‘figure’ ))==1 figure(Hf) % bring only figure forword end key=waitforbuttonpress; % pause untill user takes some action if key % key on keyboard pressed return % take no action else % object selected object=gco % get object selected by buttonpress type=get(object, ‘Type’ ); if all(type(1:4)==arg(1:4)) % delete only if ‘Type’ is correct delete(object)
在编写句柄图形函数的M文件时,函数mmap描述了一种很有用的技术。它利用函数 waitforbuttonpress和gco的结合用鼠标来获取所选定对象的句柄。 waifortbuttonpress是一个 MATLAB内置函数,它的功能是等待鼠标点击或按键。它的帮助文本如下: > help waitforbuttonpress WAITFOR BUTTONPRESS Wait for key/buttonpress over figure T- WAITFOR BUTTONPRESS stops program execution untill a key or mouse button is pressed over a figure window Returns when terminated by a mouse buttonpress, or when terminated by a keypress. Additional information about the terminating event is available from the current figure See alSo INPUt gce 帮助信息 WAITFORBUTTONPRESS等待一个鼠标/按钮对图形按下 T= WAITFORBUTTONPRESS停止程序的执行,直到鼠标按钮或键在一个图形窗口按下。 当鼠标按钮按下时返回0:当键按下时返回1。其它的结束事件的信息可从当前的图形中窗口 获取。 参阅 GINPUT和GCF 鼠标按钮在鼠标指针指的图形上按下后,函数gco返回所点中对象的句柄。然后,该句柄 可用来操作选中的对象。在精通MA∏LAB工具箱中,用这种简单的选择技术的函数还有 mmline 和 mmaxes。其中, mmline的M文件描述如下 function mmline(argl, arg2, arg3, arg 4, arg 5, arg6) %MMLINE Set Line Properties Using Mouse MMLINE waites for a mouse click on a line then applies the desired properties to the selected line Properties are given in parts, e.g., MMLINE Name value %o Properties VaLUe default o color TY m crgbwk] or an RGB in quotes: ' bl style mark points for linewidth (0.5)
end end 在编写句柄图形函数的 M 文件时,函数 mmzap 描述了一种很有用的技术。它利用函数 waitforbuttonpress 和 gco 的结合用鼠标来获取所选定对象的句柄。waifortbuttonpress 是一个 MATLAB 内置函数,它的功能是等待鼠标点击或按键。它的帮助文本如下: » help waitforbuttonpress WAITFOR BUTTONPRESS Wait for key/buttonpress over figure. T= WAITFOR BUTTONPRESS stops program execution untill a key or mouse button is pressed over a figure window.Returns 0 when terminated by a mouse buttonpress,or 1 when terminated by a keypress.Additional information about the terminating event is available from the current figure. See also GINPUT,GCF. 帮助信息: WAITFORBUTTONPRESS 等待一个鼠标/按钮对图形按下。 T=WAITFORBUTTONPRESS 停止程序的执行,直到鼠标按钮或键在一个图形窗口按下。 当 鼠标按钮按下时返回 0;当键按下时返回 1。其它的结束事件的信息可从当前的图形中窗口 获取。 参阅 GINPUT 和 GCF。 鼠标按钮在鼠标指针指的图形上按下后,函数 gco 返回所点中对象的句柄。然后,该句柄 可用来操作选中的对象。在精通 MATLAB 工具箱中,用这种简单的选择技术的函数还有 mmline 和 mmaxes。其中,mmline 的 M 文件描述如下: function mmline(arg1,arg2, arg3, arg4, arg5, arg6) %MMLINE Set Line Properties Using Mouse % MMLINE waites for a mouse click on a line then applies the desired properties to the % selected line. % Properties are given in parts,e.g.,MMLINE Name value... % Properties: % NAME VALUE{default} % color [Y m c r g b w k] or an RGB in quotes: ‘[r g b]’ % style [- -- ; -.] % mark [o + . * X] % width points for linewidth {0.5}
sIze points for marker size 16: (n a) delete selected line Examples MMLINE color r width 2 sets color to red and width to 2 points MMLINE mark size 8 sets marker type to and size to 8 points % Clicking on an object other than a line, or striking a key on the keyboard aborts the command Copyright (c) 1996 by Prentice-Hall, Inc if isempty(Hf), error( No Figure Avaiable. ), end if length(get(O, Children))==1 figure(Hf) bring only figure forword end key=waitforbuttonpress if key key on keyboard pressed return object selecte if st for i-1: 2: max(nargin-1, 1) Name=eval(sprintf(arg%.Of', 1), ) get Name argument value=eval(sprintf(arg%.0f, 1+1)); get value if strcmp(Name, color') t(Hl, color set(HI, Linestyle (HI, Linestyle, value elseif strcmp(Name, width) value=abs(eval( value)
% size points for marker size {6} % zap (n.a.) delete selected line % Examples: % MMLINE color r width 2 sets color to red and width to 2 points % MMLINE mark + size 8 sets marker type to + and size to 8 points % % Clicking on an object other than a line,or striking a key on the keyboard aborts the % command. % Copyright (c) 1996 by Prentice-Hall,Inc. Hf=mmgcf; if isempty(Hf),error( ‘No Figure Avaiable.’ ),end if length(get(0, ‘Children’ ))==1 figure(Hf) % bring only figure forword end key=waitforbuttonpress; if key % key on keyboard pressed return else % object selected Hl=gco if strcmp(get(Hl, ‘Type’ ), ‘line’ ) % line object selected for i=1:2:max(nargin-1,1) Name=eval(sprintf( ‘arg%.0f ‘ ,i),[]); get Name argument if strcmp(Name, ‘zap’ ) delete(Hl),return end value=eval(sprintf( ‘arg%.0f ‘ ,i+1),[]); % get value if strcmp(Name, ‘color’ ) set(Hl, ‘Color’ ,value) elseif strcmp(Name, ‘style’ ) set(Hl, ‘Linestyle’ ,value) elseif strcmp(Name, ‘mark’ ) set(Hl, ‘Linestyle’ ,value) elseif strcmp(Name, ‘width’ ) value=abs(eval(value)) set(Hl, ‘LineWidth’ ,value) elseif strcmp(Name, ‘size’ ) value=abs(eval(value)) set(Hl, ‘MarkerSize’ ,value) else
displl' Unknown Property Name: NameD) 精通MA∏LAB工具箱中的函数 mmpaper以简单的方式阐述了对纸张属性的使用。如下所 示,函数 mmpaper设置当前图形的纸张属性,并将所有以后的图形设成缺省值。函数 mmpage 在下一章讨论,它是一个 mmpaper友函数。 mmpage建立一个图形用户界面,设定图形在打印 页上的位置 function mmpaper(argl, arg2, arg3, arg 4, arg5, arg6) %MMPAPER Set Default Paper Properties MMPAPER Name value sets default paper properties for the current figure and succeeding figures based on Name value pairs NAME VaLUe default) Units [inches), centimeters, points, normal] [portrait), landscape %o type Iusletter), uslegal, a3, a4letter, a5, b4, tabloid % Examples MMPAPER Units inch orient landscape MMPAPER type tabloid %o MMPAPER with no arguments returns the current paper defaults %o Copyright (c) 1996 by Prentice-Hall, Inc flag=0 if isempty(Hf) flag=l Hf-figure( "Visible, 'off) if nargin for i=1: 2 max( nargin-l, 1) Name=eval(sprintf(arg%.0f, 10, get Name argument valueseval(sprintf(arg%.0f, i+1)o, get Name argument if Name(1)==o
disp([ ‘Unknown Property Name: ‘ Name’]) end end end end 精通 MATLAB 工具箱中的函数 mmpaper 以简单的方式阐述了对纸张属性的使用。如下所 示,函数 mmpaper 设置当前图形的纸张属性,并将所有以后的图形设成缺省值。函数 mmpage 在下一章讨论,它是一个 mmpaper 友函数。mmpage 建立一个图形用户界面,设定图形在打印 页上的位置。 function mmpaper(arg1,arg2,arg3,arg4,arg5,arg6) %MMPAPER Set Default Paper Properties. % MMPAPER Name value... % sets default paper properties for the current figure and succeeding figures based on Name % value pairs. % Properties: % NAME VALUE {default} % Units [{inches},centimeters,points,normal] % orient [{portrait},landscape] % type [{usletter},uslegal,a3,a4letter,a5,b4,tabloid] % % Examples: % MMPAPER Units inch orient landscape % MMPAPER type tabloid % % MMPAPER with no arguments returns the current paper defaults. % Copyright (c) 1996 by Prentice-Hall,Inc. Hf=mmgcf; flag=0; if isempty(Hf) flag=1; Hf=figure( ‘Visible’ , ‘off ‘ ); end if nargin for i=1:2:max(nargin-1,1) Name=eval(sprintf( ‘arg%.0f ‘ ,i)0,[]); % get Name argument value=eval(sprintf( ‘arg%.0f ‘ ,i+1)0,[]); % get Name argument if Name(1)== ‘o’
set(O, DefaultFigurePaperOrientation,, value) set(Hf, "PaperOrientation,, value) set(O, DefaultFigurePaper Type, value) set(Hf, "Paper Type, value) elseif Name(1)==u set(O, DefaultFigurePaper Units, value) else set(Hf, "Paper Units', value) disp(l 'Unknown Property Name: Name)) 当把对象放在一个特定的位置时,有时在象素和归一化坐标之间进行转化是很有用的。在 精通MA∏LAB工具箱中有两个函数进行这种转换。第一个是mmpx2n,它将象素转化为归 化坐标;第二个是mmn2px,它进行相反的转换。这些函数演示了如何以所需的一组单位获取 Position’属性值。首先,把对象的当前" Units属性保存起来:;然后,将" Units'属性设成所 需的值并获取所需的 Position’属性值;最后,将Unis'的值恢复为初始值。mmpx2n的M 文件描述如下: function Y=mmpx2n(X, Hf %MMPX2N Pixel to Normalized Coordinate Transformation MMPX2N(X)converts the Position vector x from pixel coordinates to normalized coordinates w r.t. the computer screen MMPX2N converts the Position vector X from pixel coordinate to narmalized coordinates w.r. t the figure window having handle H % X=lleft bottom width height] or X=width height Copyright (c) 1996 by Prentice-Hall, Inc msg=Input is not a pixel Position vector length(X) if nargin==l, Hf=0 SZ="ScreenSize; end if any (X<l)l(lx-=4&lx-=2)
set(0, ‘DefaultFigurePaperOrientation’ ,value) set(Hf, ‘PaperOrientation’ ,value) elseif Name(1)== ‘t’ set(0, ‘DefaultFigurePaperType’ ,value) set(Hf, ‘PaperType’ ,value) elseif Name(1)== ‘u’ set(0, ‘DefaultFigurePaperUnits’ ,value) set(Hf, ‘PaperUnits’ ,value) else disp([ ‘Unknown Property Name:’ Name]) ens end end 当把对象放在一个特定的位置时,有时在象素和归一化坐标之间进行转化是很有用的。在 精通 MATLAB 工具箱中有两个函数进行这种转换。第一个是 mmpx2n,它将象素转化为归一 化坐标;第二个是 mmn2px,它进行相反的转换。这些函数演示了如何以所需的一组单位获取 ‘Position’ 属性值。首先,把对象的当前 ‘Units’ 属性保存起来;然后,将 ‘Units’ 属性设成所 需的值并获取所需的 ‘Position’ 属性值;最后,将 ‘Units’ 的值恢复为初始值。mmpx2n 的 M 文件描述如下: function Y=mmpx2n(X,Hf) %MMPX2N Pixel to Normalized Coordinate Transformation. % MMPX2N(X) converts the Position vector X from pixel coordinates to normalized % coordinates w.r.t.the computer screen. % % MMPX2N converts the Position vector X from pixel coordinate to narmalized coordinates % w.r.t.the figure windoiw having handle H. % % X=[left bottom width height] or X=[width height] % Copyright (c) 1996 by Prentice-Hall,Inc. msg= ‘Input is not a pixel Position vector.’ ; lx=length(X); sz= ‘Position’ ; if nargin==1,Hf=0;sz= ‘ScreenSize’ ;end if any(X<1)| (lx~=4&lx~=2) error(msg)
if lx==2, X=[l 1 X(l; end [width height] input format Is); set U s=get(Hf, sz) =(X-1)/([S(3:4)]-1) set(Hf, Units, u); reset Units if any(Y>1) f lx==2, Y=Y(3: 4); end width height]output format 精通 MATLAB工具箱中的两个函数 mmcont2和 mmcont3都用用户指定的颜色映象画等 值线图。每一个函数分析输入参量并建立一个字符串,它包含了颜色的说明。一旦设置了字符 串,就设置了当前坐标轴的 ColorOrder’属性;最后,它们分别调用具有合适的参量的函数 contour和 contour3来画出图形。函数 mmcont2的M文件描述如下 function( cs, h=mmcont2(argl, arg2, arg3, arg 4, arg5) %MMCONT2 2-D contour plot using a colormap %o MMCONT2(X,Y, Z, N, C)plots N contours of Z in 2-D using the color %o specified in CC can be a linestyle and color as used in plot, % e.g., T-, orC can be the string Name of a colormap. X and Y define the axis limits If not given default argument values are: N=10, C=hot X and Y =row and column indices of Z. Examples MMCONT2(Z 10 lines with hot colormap MMCONT2(Z, 20) 20 lines with hot colormap MMCONT2(Z, copper') 0 lines with copper colormap MMCONT2(Z, 20, 'gray) 20 lines with MMCONT2(X,Y, Z, jet) 10 lines with jet colormap %o MMCONT2(Z,c-) 10 dashed lines in cyan MMCONT2(X,Y, Z, 25, pink) 25 lines in pink colormap CSMMCONT2(.)returns the contour matrix CS as described CONTOURO [CS, H=MMCONT2(.)returns a column vector H of handles to Copyright(c)1996 by Prentice-Hall, Inc n=10: c="hot. default values
end if lx==2,X=[1 1 X(:)’ ];end % [width height] input format u=get(Hf, ‘Units’ ); % get Units set (Hf, ‘Units’ , ‘pixels’ ); % set Units to pixels s=get(Hf,sz); Y=(X-1)./([s(3:4)]-1); % convert set(Hf, ‘Units’ ,u); % reset Units if any(Y>1) error(msg) end if lx==2,Y=Y(3:4);end % [width height] output format 精通 MATLAB 工具箱中的两个函数 mmcont2 和 mmcont3 都用用户指定的颜色映象画等 值线图。每一个函数分析输入参量并建立一个字符串,它包含了颜色的说明。一旦设置了字符 串,就设置了当前坐标轴的 ‘ColorOrder’ 属性;最后,它们分别调用具有合适的参量的函数 contour 和 contour3 来画出图形。函数 mmcont2 的 M 文件描述如下: function[cs,h]=mmcont2(arg1,arg2,arg3,arg4,arg5) %MMCONT2 2-D contour plot using a colormap. % MMCONT2(X,Y,Z,N,C) plots N contours of Z in 2-D using the color % specified in C.C can be a linestyle and color as used in plot, % e.g., ‘r-’ ,orC can be the string Name of a colormap. X and Y % define the axis limits. % If not given default argument values are: N=10,C= ‘hot’ , % X and Y =row and column indices of Z. Examples: % MMCONT2(Z) 10 lines with hot colormap % MMCONT2(Z,20) 20 lines with hot colormap % MMCONT2(Z, ‘copper’ ) 10 lines with copper colormap % MMCONT2(Z,20, ‘gray’ ) 20 lines with gray colormap % MMCONT2(X,Y,Z, ‘jet’ ) 10 lines with jet colormap % MMCONT2(Z, ‘c-’ ) 10 dashed lines in cyan % MMCONT2(X,Y,Z,25, ‘pink’ ) 25 lines in pink colormap % % CS=MMCONT2(…) returns the contour matrix CS as described in % CONTOURC. % [CS,H]=MMCONT2(…) returns a column vector H of handles to % line objects. % Copyright (c) 1996 by Prentice-Hall,Inc. n=10;c= ‘hot’ ; % default values nargs=nargin;cflag=1;
if nargin<l, error( Not enough input arguments. ),end for i=2 nargin check input arguments for N and C argieval(sprintf(arg%Of, 1)); if -isstr(argi)&length(argi==l must be N, grab it nargs=1;% args to pass to contour elseif isstr(argi) must be C if exist(argi)==2 is colormap, so grab it else is single color/linestyle nargs-I, if cflag a colormap has been chosen clf clear figure hold on hold it mapstr=sprintf(c(%.0f)'I,n) set(gca, Color Order, eval( mapstr)) evalstr="[CS, H]=contour( fc or -l nar levalstr sprintf(arg%.0f, 1)7I: Istr=length(evalstr) evalstr(lstr: Istr+1)=) eval(evalstr) if nargout=I sCS elseif nargout==2, ECS: h=H d 这里要讨论的最后一个精通 MATLA B工具箱函数是 motile。就象在二维函数那一章里所 描述的一样,该函数在计算机屏幕上将4个已存在的图形按平铺模式排列起来。函数 motile.m 的内容如下所示:
if nargin<1,error( ‘Not enough input arguments.’ ), end for i=2:nargin % check input arguments for N and C argi=eval(sprintf( ‘arg%.0f ‘ ,i)); if ~isstr(argi)&length(argi)==1 % must be N, grab it n=argi; nargs=i; % # args to pass to contour2 elseif isstr(argi) % must be C if exist(argi)==2 % is colormap,so grab it c=argi; nargs=i-1; else % is single color/linestyle cflag=0; nargs=i; end end end if cflag % a colormap has been chosen clf % clear figure view(2) % make it 2-D hold on % hold it mapstr=sprintf([c ‘(%.0f)’ ],n); set(gca,’ColorOrder’,eval(mapstr)); end evalstr=‘[CS,H]=contour(’; for i=1:nargs evalstr=[evalstr sprintf( ‘arg%.0f ‘ ,i) ‘,’ ]; end lstr=length (evalstr); evalstr(lstr:lstr+1)= ‘);’ ; eval(evalstr) hold off if nargout==1, cs=CS; elseif nargout==2, cs=CS;h=H; end 这里要讨论的最后一个精通 MATLAB 工具箱函数是 mmtile。就象在二维函数那一章里所 描述的一样,该函数在计算机屏幕上将 4 个已存在的图形按平铺模式排列起来。函数 mmtile.m 的内容如下所示: function h=mmtile(n)
MMTILE Tile Figure Windows MMTILE with no arguments, tiles the current figure windows and brings them to the foreground. Figure size is adjusted so that 4 figure windows fit on the screen Figures are arranged in a clockwise fashion starting in the r-left corner of the display % MMTILE(N)makes tile n the current figure if it exists Otherwise, the next tile is created for subsequent plotting Tiled figure windows are titled TILE #l, TILE #2, TILE #3, TILE #4 %o Copyright(c)1996 by Prentice-Hall, Inc HT=40 %tile height fudge in pixels WD=20: tilo bigger fudge numbers increase gaps between iles Hf=sort(get(0,‘ Children’); get handles of current figures nHf-length(Hf) set(O,Units, 'Pixels)% set screen dimensions to pixels SZ=get(O, 'Screensize'); get screen size in pixels tsz=0. 9*sz(3: 4); defaut tile area is almost whole monitor if sz(4)>sz(3), if portrait monitor z 2)=. tsz(1); take a landscape chunl tsz=min( tsz, [920 690)); hold tile area on large screens to 920 by 690 tI(l, 1=sz(3)-tsz(1)+l; left side of left tiles tl(2, 1)=tl(1, 1)+tsz(1)/2; left side of right tiles tb(1, 1 )=sz(4)-tsz(2)+1; bottom of bottom tiles tb(2, 1)=tb(1, 1)+tsz(2)/2, bottom of top tiles tpos=zeros(4); matrix holding tile Position vectors tpos(, 1)=tI(1],);% left sides tpos(:,2)=t1(2211],1);% bottoms tpos(:, 3=(tsz( 1)/2-WD)*ones(4, 1):% tpos(: 4 =(tsz(2)/2-HT"ones(4, 1);% heights tpos=fix( tpos); make sure pixel Positions are integers if nargin==0 tile figures as needed for i=l: min(nHf, 4)
% MMTILE Tile Figure Windows. % MMTILE with no arguments, tiles the current figure windows % and brings them to the foreground. % Figure size is adjusted so that 4 figure windows fit on the screen. % Figures are arranged in a clockwise fashion starting in the % upper-left corner of the display % % MMTILE(N) makes tile N the current figure if it exists. % Otherwise, the next tile is created for subsequent plotting % % Tiled figure windows are titled TILE #1,TILE #2, TILE #3, TILE #4. % Copyright (c) 1996 by Prentice-Hall,Inc. HT=40; %tile height fudge in pixels WD=20; % tile width fudge % adjust the above as necessary to eliminate tile overlaps % bigger fudge numbers increase gaps between tiles Hf=sort(get(0,‘Children’)); % get handles of current figures nHf=length(Hf); set(0, ‘Units’ ,‘Pixels’) % set screen dimensions to pixels sz=get(0,‘Screensize’); % get screen size in pixels tsz=0.9*sz(3:4); % defaut tile area is almost whole monitor if sz(4)>sz(3), % if portrait monitor tsz(2)=.75*tsz(1); % take a landscape chunk end tsz=min(tsz,[920 690]); % hold tile area on large screens to 920 by 690 t1(1,1)=sz(3)-tsz(1)+1; % left side of left tiles t1(2,1)=t1(1,1)+tsz(1)/2; % left side of right tiles tb(1,1)=sz(4)-tsz(2)+1; % bottom of bottom tiles tb(2,1)=tb(1,1)+tsz(2)/2; % bottom of top tiles tpos=zeros(4); % matrix holding tile Position vectors tpos(:,1)=t1([1 2 2 1],1); % left sides tpos(:,2)=t1([2 2 1 1],1); % bottoms tpos(:,3)=(tsz(1)/2-WD)*ones(4,1); % widths tpos(:,4)=(tsz(2)/2-HT)*ones(4,1); % heights tpos=fix(tpos); % make sure pixel Positions are integers if nargin==0 % tile figures as needed for i=1:min(nHf,4)
Hf(i),“Ur if any(get(Hf(i) 0s(1,) set(Hf(i),'Position, tpos(i, Name’,[‘TLE#’int2str(i)) figure( Hf(D) else go to tile n or create it n=rem(abs(n)-1, 4)+1; Nmust be between I and 4 if n<=nHf tile n exists, make it current figure(Hf(n)) else tile n does not exist. create next one n=nHf+1 Number title’,‘off Name’,[‘TLE#’int2str(n)]) 如上面所描述的,函数 motile从根对象得到所有的图形对象的句柄和屏幕尺寸,为该图形 计算新的位置和尺寸,然后设置每个图形的 Units," Position', Number’和'Name’属性 它具有安置和缩放图形的效能,并在每个窗口标题中,改变名字字符串。HT和WT给出的号 码与计算机平台有关。它们对图形的" Position’描述窗口内的可画区域而不是外部尺寸有补偿 作用。 20.12属性名和属性值 下面各表中列出了 MATLAB42版本中的属性名和属性值。有一个星号*的属性是非文件 化的。用大括号{}括起来的属性值是缺省值。 表20.3 根对象属性 BlackAndwhite 自动硬件检测标志 on:认为显示是单色的,不检测 {of:检测显示类型 Vlaxkoutunusedslots 值为{no}yes * Capture Ma Capture Matrix 由 Capturerect矩形所包围的区域内图象数据的只读 阵,使用 Image来显示 aptureRect 捕捉矩形的尺寸和位置 个4元素的向量
set(Hf(i),‘Units’,‘pixels’) if any(get(Hf(i),‘Position’)~=tpos(i,:)) set(Hf(i),‘Position’,tpos(i,:),… ‘NumberTitle’,‘off’,… ‘Name’,[‘TILE #’int2str(i)]) end figure(Hf(i)) end else % go to tile N or create it n=rem(abs(n)-1,4)+1; % N must be between 1 and 4 if n<=nHf % tile N exists,make it current figure(Hf(n)) else % tile N does not exist,create next one n=nHf+1; figure(‘Position’,tpos(n,:),… ‘NumberTitle’,‘off’,… ‘Name’,[‘TILE #’int2str(n)]) end end 如上面所描述的,函数 mmtile 从根对象得到所有的图形对象的句柄和屏幕尺寸,为该图形 计算新的位置和尺寸,然后设置每个图形的 ‘Units’ , ‘Position’ , ‘Number’ 和 ‘Name’ 属性。 它具有安置和缩放图形的效能,并在每个窗口标题中,改变名字字符串。HT 和 WT 给出的号 码与计算机平台有关。它们对图形的 ‘Position’ 描述窗口内的可画区域而不是外部尺寸有补偿 作用。 20.12 属性名和属性值 下面各表中列出了 MATLAB 4.2 版本中的属性名和属性值。有一个星号*的属性是非文件 化的。用大括号{}括起来的属性值是缺省值。 表 20.3 根对象属性 BlackAndWhite on: {off}: 自动硬件检测标志 认为显示是单色的,不检测; 检测显示类型 *VlaxkOutUnusedSlots 值为[{no}|yes] *CaptureMap CaptureMatrix 由 CaptureRect 矩形所包围的区域内图象数据的只读 矩阵,使用 image 来显示 CaptureRect 捕捉矩形的尺寸和位置,是一个 4 元素的向量