Getting Started Previous page   Next Page

Setting Object Properties

All object properties have default values. However, you might find it useful to change the settings of some properties to customize your graph. There are two ways to set object properties:

Setting Properties from Plotting Commands

You can specify object property value pairs as arguments to many plotting functions, such as plot, mesh, and surf.

For example, plotting commands that create lineseries or surfaceplot objects enable you to specify property name/property value pairs as arguments. The command

plots the data in the variables x, y, and z using a surfaceplot object with interpolated face color and employing the Gouraud face light technique. You can set any of the object's properties this way.

Setting Properties of Existing Objects

To modify the property values of existing objects, you can use the set command or the Property Editor. This section describes how to use the set command. See Using the Property Editor for more information.

Most plotting functions return the handles of the objects that they create so you can modify the objects using the set command. For example, these statements plot a five-by-five matrix (creating five lineseries, one per column) and then set the Marker property to a square and the MarkerFaceColor property to green:

In this case, h is a vector containing five handles, one for each of the five lineseries in the graph. The set statement sets the Marker and MarkerFaceColor properties of all lineseries to the same values.

Setting Multiple Property Values

If you want to set the properties of each lineseries to a different value, you can use cell arrays to store all the data and pass it to the set command. For example, create a plot and save the lineseries handles:

Suppose you want to add different markers to each lineseries and color the marker's face color the same color as the lineseries. You need to define two cell arrays -- one containing the property names and the other containing the desired values of the properties.

The prop_name cell array contains two elements:

The prop_values cell array contains 10 values: five values for the Marker property and five values for the MarkerFaceColor property. Notice that prop_values is a two-dimensional cell array. The first dimension indicates which handle in h the values apply to and the second dimension indicates which property the value is assigned to:

The MarkerFaceColor is always assigned the value of the corresponding line's color (obtained by getting the lineseries Color property with the get command).

After defining the cell arrays, call set to specify the new property values:


Previous page  Graphics Objects Specifying the Axes or Figure Next page

© 1994-2005 The MathWorks, Inc.