set(O, DefaultFigurePaperOrientation,, value) set(Hf, "PaperOrientation,, value) elseif Name(1)==t set(O, DefaultFigurePaper Type, value) set(Hf, " Paper Type, value elseif Name(1)==u set(O, DefaultFigurePaper Units, value) 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和 emcon3都用用户指定的颜色映象画等 值线图。每一个函数分析输入参量并建立一个字符串,它包含了颜色的说明。一旦设置了字符 串,就设置了当前坐标轴的 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 argi=eval( sprintf(arg%Of, 1)); if-isstr(argi)&length(argi)==1 must be n, grab it -ar nargs=i; args to pass to contour 2 elseif isstr(argi) must be C if exist(argi)==2 is colormap, so grab it nargs=i-1 else is single color/linestyle nargs-I, if cflag a colormap has been chosen clf clear figure view(2) make it 2-D hold on hold it mapstr=sprintf(c(%.0f)'I,n) set(gca, Color Order, eval( mapstr)) evalstr='CS, H=contour( fc or -l nar evalstr=levalstr sprintf(arg%.0f, 1)7I; Istr=length(evalstr) evalstr(lstr: Istr+1)=) eval(evalstr) if nargout=I sCS elseif nargout==2, cS=CS; 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 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 tiles Hf=sort( get(O, 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 figure fori=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 fany(get(Hf(i),‘ Position’)=tpos(i:) 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} i lyes * 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 元素的向量