Graphics |
Example -- Creating Core Graphics Objects
Object creation functions have a syntax of the form
You can specify a value for any object property (except those that are read only) by passing property name/value pairs as arguments. The function returns the handle of the object it creates, which you can use to query and modify properties after creating the object.
This example evaluates a mathematical function and creates three graphics objects using the property values specified as arguments to the figure
, axes
, and surface
commands. MATLAB uses default values for all other properties.
[x,y] =meshgrid
([-2:.4:2]); Z = x.*exp(-x.^2-y.^2); fh =figure
('Position',[350 275 400 300],'Color','w'); ah =axes
('Color',[.8 .8 .8],'XTick',[-2 -1 0 1 2],... 'YTick',[-2 -1 0 1 2]); sh =surface
('XData',x,'YData',y,'ZData',Z,... 'FaceColor',get(ah,'Color')+.1,... 'EdgeColor','k','Marker','o',... 'MarkerFaceColor',[.5 1 .85]);
Note that the surface
function does not use a 3-D view like the high-level surf
functions. Object creation functions simply add new objects to the current axes without changing axes properties, except the Children
property, which now includes the new object and the axis limits (XLim
, YLim
, and ZLim
), if necessary.
You can change the view using the camera commands or use the view
command.
Core Graphics Objects | Parenting |
© 1994-2005 The MathWorks, Inc.