wildgoat的个人空间 https://blog.eetop.cn/wildgoat [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

[Matlab] Setting Default Property Values

已有 1597 次阅读| 2012-8-31 12:52 |个人分类:Matlab

Factory- and User-Defined Values

All object properties have values built into MATLAB  (i.e.,factory-defined values). You can also define your own default valuesat any point in the object hierarchy. 


You cannot define default values for plotobjects.


How MATLAB  Searches for Default Values

MATLAB searches for a default value beginning with thecurrent object and continuing through the object's ancestors untilit finds a user-defined default value or until it reaches the factory-definedvalue. Therefore, a search for property values is always satisfied.


The closer to the root of the hierarchy you define the default,the broader its scope. If you specify a default value for line objectson the root level, MATLAB uses that value for all lines becausethe root is at the top of the hierarchy. If you specify a defaultvalue for line objects on the axes level, MATLAB uses that valuefor line objects drawn only in that axes.


If you define default values on more than one level, the valuedefined on the closest ancestor takes precedence because MATLAB terminatesthe search as soon as it finds a value. 


Setting default values affects only those objects created afteryou set the default. Existing graphics objects are not affected.


Thisdiagram shows the steps MATLAB follows in determining the valueof a graphics object property.


Defining Default Values

To specify default values, create a string beginning with theword Default, followed by the object type, andfinally, by the object property. For example, to specify a defaultvalue of 1.5 points for the line property LineWidthatthe level of the current figure, use the statement

       set(gcf,'DefaultLineLineWidth',1.5) 


The string DefaultLineLineWidthidentifiesthe property as a line property. To specify the figure color, use DefaultFigureColor.It is meaningful to specify a default figure color only on the rootlevel.

      set(0,'DefaultFigureColor','b') 


Use getto determinewhat default values are currently set on any given object level:

      get(gcf,'default')

returns all default values set on the current figure.


Setting Properties to the Default

Specifying a property value of 'default'setsthe property to the first encountered default value defined for thatproperty. For example, these statements result in a green surface EdgeColor:

      set(0,'DefaultSurfaceEdgeColor','k')

      h = surface(peaks); 

      set(gcf,'DefaultSurfaceEdgeColor','g') 

      set(h,'EdgeColor','default')


Because a default value for surface EdgeColorexistson the figure level, MATLAB encounters this value first and usesit instead of the default EdgeColordefined onthe root.


Removing Default Values

Specifying a property value of 'remove'getsrid of user-defined default values. The statement

      set(0,'DefaultSurfaceEdgeColor','remove')

removes the definition of the default Surface EdgeColorfromthe root.


Setting Properties to Factory-Defined Values

Specifying a property value of 'factory'setsthe property to its factory-defined value. (The propertydescriptionsprovides access to the factory settings for properties having predefinedsets of values.) 


For example, these statements set the EdgeColorofsurface hto black (its factory setting), regardlessof what default values you have defined:

      set(gcf,'DefaultSurfaceEdgeColor','g') 

      h = surface(peaks); 

      set(h,'EdgeColor','factory')


Reserved Words

Setting a property value to default, remove,or factoryproduces the effects described in theprevious sections. To set a property to one of these words (e.g.,a text or uicontrolStringpropertyset to the word default), you must precede theword with the backslash character:

      h = uicontrol('Style','edit','String','\default');


Examples — Setting Default Line Styles

The plotfunction cyclesthrough the colors defined by the axes ColorOrderpropertywhen displaying multiline plots. If you define more than one valuefor the axes LineStyleOrderproperty, MATLAB incrementsthe line style after each cycle through the colors.


You can set default property values that cause the plotfunctionto produce graphs using varying line styles, but not varying colors.This is useful when you are working on a monochrome display or printingon a black and white printer. 


First Example

This example creates a figure with a white plot (axes) backgroundcolor, and then sets default values for axes objects on the root level:

      whitebg('w') %create a figure with a white color scheme

      set(0,'DefaultAxesColorOrder',[0 0 0],... 

               'DefaultAxesLineStyleOrder','-|--|:|-.')


Whenever you call plot,

      Z = peaks; plot(1:49,Z(4:7,:))

it uses one color for all data plotted because the axes ColorOrdercontainsonly one color, but it cycles through the line styles defined for LineStyleOrder.

Second Example

This example sets default values on more than one level in thehierarchy. These statements create two axes in one figure window,setting default values on the figure level and the axes level:        

        t = 0:pi/20:2*pi;
        s = sin(t);
        c = cos(t);
        % Set default value for axes Color property
        figh = figure('Position',[30 100 800 350],... 
                      'DefaultAxesColor',[.8 .8 .8]); 
        
        axh1 = subplot(1,2,1); grid on
        % Set default value for line LineStyle property in first axes
        set(axh1,'DefaultLineLineStyle','-.')
        line('XData',t,'YData',s) 
        line('XData',t,'YData',c) 
        text('Position',[3 .4],'String','Sine')
        text('Position',[2 -.3],'String','Cosine',...
             'HorizontalAlignment','right')
        
        axh2 = subplot(1,2,2); grid on
        % Set default value for text Rotation property in second axes
        set(axh2,'DefaultTextRotation',90)
        line('XData',t,'YData',s) 
        line('XData',t,'YData',c) 
        text('Position',[3 .4],'String','Sine')
        text('Position',[2 -.3],'String','Cosine',...
             'HorizontalAlignment','right') 


Issuing the same lineand textstatements to each subplot regionresults in a different display, reflecting different default settings.

Because the default axes Colorpropertyis set on the figure level of the hierarchy, MATLAB creates bothaxes with the specified gray background color.


The axes on the left (subplot region 121) defines a dash-dotline style (-.) as the default, so each call tothe linefunction uses dash-dot lines. The axeson the right does not define a default line style, so MATLAB usessolid lines (the factory setting for lines). 


The axes on the right defines a default text Rotationof90 degrees, which rotates all text by this amount. MATLAB obtainsall other property values from their factory settings, which resultsin nonrotated text on the left.


To install default values whenever you run MATLAB,specify them in your startup.mfile. MATLAB mightinstall default values for some appearance properties when startedby calling the colordefcommand. 


(source:http://www.mathworks.co.jp/help/techdoc/creating_plots/f7-21465.html)

点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 122

    粉丝
  • 42

    好友
  • 273

    获赞
  • 118

    评论
  • 22104

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-5 11:49 , Processed in 0.014050 second(s), 7 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部