MATLAB Programming/Handle Graphics

From Wikibooks, open books for an open world
Jump to navigation Jump to search

This book discusses some ways of manipulating graphics in MATLAB.

What is a handle?[edit | edit source]

All of the graphics capabilities explained thus far are ways to generate plots without worrying much about the details. However, very often, you will want a plot that looks a very specific way. You can go into the GUI and change all of the settings every time, but this gets very tedious and wastes a lot of time. If you want a way to generate a plot that has the same look all the time, it is time to delve into the realm of handle graphics.

A handle is a floating-point scalar that points to a large list of different properties. Each element of a plot has its own properties, and its own handle. Handles are organized into a tree-structured hierarchy, starting from the handle for your monitor (named 0) and branching down to separate handles for children like axis labels, text annotations, error bars, and anything else that can go on a plot. Handles at all levels can be controlled interactively or adjusted programmatically, by changing the values of the handle properties using specific functions.

Monitor properties: the 0 handle[edit | edit source]

Monitor properties are useful to know when designing graphic user interfaces. For example, you may want to check that a figure window fits inside the user's screen. In order to get a list of the properties of the screen, type:

>> get(0)

To get a specific property, type

>> get(0, 'propertyname');

See the documentation for a complete list of property names and what they mean.

Axis handles[edit | edit source]

See the documentation for a list of valid axis properties and values of those properties.

gca[edit | edit source]

Other types of handles[edit | edit source]

Text handles[edit | edit source]

uicontrols[edit | edit source]