Graphics Previous page   Next Page

Defining Custom Pointers

When you set the Pointer property to custom, MATLAB displays the pointer you define using the PointerShapeCData and the PointerShapeHotSpot properties. Custom pointers are 16-by-16 pixels, where each pixel can be either black, white, or transparent.

Specify the pointer by creating a 16-by-16 matrix containing elements that are

Assign the matrix to the figure PointerShapeCData property. MATLAB displays the defined pointer whenever the pointer is in the figure window.

The PointerShapeHotSpot property specifies the pixel that indicates the pointer location. MATLAB then stores this location in the root PointerLocation property. Set the PointerShapeHotSpot property to a two-element vector specifying the row and column indices in the PointerShapeCData matrix that correspond to the pixel specifying the location. The default value for this property is [1 1], which corresponds to the upper left corner of the pointer.

Example -- Two Custom Pointers

One way to create a custom pointer is to assign values to a 16-by-16 matrix by hand, as illustrated in the following example.

First, initialize the matrix, setting all values to 2. Create a black border 1 pixel wide. Add alignment marks.

The last statement sets the Pointer property to custom, assigns the matrix to the PointerShapeCData property, and selects element (9,9) as the "hot spot."

MATLAB now uses the custom pointer within the figure window.

Creating Pointers from Functions.   You can use a mathematical function to define the PointerShapeCData matrix. For example, evaluating the function

produces an interesting surface.

Use the values of Z to create a pointer sampling fewer points so that Z is a 16-by-16 matrix.

The statement flipud((Z>0) + 1) sets all values in Z that are greater than 0 to 2 (in MATLAB, true + 1 = 2), less than 0 to 1 (false + 1 = 1) and then flips the data around so that element (1,1) is the upper left corner.


Previous page  Specifying the Figure Pointer Axes Properties Next page

© 1994-2005 The MathWorks, Inc.