Get, set and restore Handle Graphics objects
Updated 26 Nov 2007

No License

PUSHPROP is used to temporarily save and optionally set one or more properties of one or more Handle Graphics objects.

PUSHPROP is used in passages normally coded like this:

SavedProp = get(h, 'Property');
set(h, 'Property', newval);
% ... interact some more with object h
set(h, 'Property', SavedProp);

With PUSHPROP, the above segment can be written as

SavedProp = pushprop(h, 'Property', newval);
% ... interact some more with object h

Although it does save you one line of code, the real advantage is that the saved and restored property name(s) only need to be entered once, making the code easier to maintain and also makes the coder's intentions more transparent.

PUSHPROP closely mimics the syntax of SET, except for the output. Also, it behaves consistently for a structure array, in that it treats the elements in the array as individual setting for each handle. SET uses the last element of the struct for all objects.

% Set the current figure's background color to red for two seconds.
SavedColor=pushprop(gcf, 'Color', [1 0 0]);

Cite As

Jerker Wagberg (2024). pushprop (https://www.mathworks.com/matlabcentral/fileexchange/17669-pushprop), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Graphics Object Programming in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

Version 1.1: Now correctly handles properties that depend on the order that they are set.