No BSD License  

Highlights from
pushprop

Be the first to rate this file! 1 Download (last 30 days) File Size: 3.93 KB File ID: #17669

pushprop

by Jerker Wagberg

 

22 Nov 2007 (Updated 26 Nov 2007)

Get, set and restore Handle Graphics objects

| Watch this File

File Information
Description

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
    SavedProp.pop();

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.

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

MATLAB release MATLAB 7.5 (R2007b)
Other requirements This should work in most older releases, down to version 7.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
26 Nov 2007 J Wagberg

About three minutes after hitting the submit key for this entry, I realized that PUSHPROP will not restore properly for some combinations of properties, e.g. the sequence 'Units' followed by 'Position' would fail to restore correctly. New version has already been posted and will show up soon.

Please login to add a comment or rating.
Updates
26 Nov 2007

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

Tag Activity for this File
Tag Applied By Date/Time
data exploration Jerker Wagberg 22 Oct 2008 09:36:32
get Jerker Wagberg 22 Oct 2008 09:36:32
set Jerker Wagberg 22 Oct 2008 09:36:32
restore Jerker Wagberg 22 Oct 2008 09:36:32
handle graphics Jerker Wagberg 22 Oct 2008 09:36:32
object Jerker Wagberg 22 Oct 2008 09:36:32
property Jerker Wagberg 22 Oct 2008 09:36:32
properties Jerker Wagberg 22 Oct 2008 09:36:32

Contact us at files@mathworks.com