[MATLAB logo] Exploiting MATLAB's Data Structures

Problem #7 - Vectorized Set/Get

The get and set functions are vectorized so that when used with more than one handle all the property values can be retrieved or set in one operation. The expression

s = get(h)

returns a structure containing as fields the names of the properties for the given handles (which all must be the same type) and their associated values. The dual syntax

set(h,s)

sets all the properties at once.

The expression

val = get(h,{'prop1','prop2',...})

returns a cell array containing the specified property values for the given handles. The dual syntax

set(h,{'prop1','prop2',...},values)

is used to set the specified properties to the values in the values cell array.

You can use these expressions to vectorize operations on handle graphics objects.

Goal: Change all the text colors in an axis to their complements.

Key concepts: handles, vectorized set and get, structures, cell arrays

Key functions: set, get, findobj,

What to do

  1. Run sillytext
  2. Change all of the text colors to their complements. This means, change colors C to 1-C where C is a 1-by-3 rgb color value.

[hint] [Show me the solution]

Copyright © 1997 The MathWorks, Inc.
clay@mathworks.com
$Revision$ $Date$