File Exchange

image thumbnail

HandleGraphicsSetGe​t class

version (74.2 KB) by Andrew Newell
An extension of the handle graphics set/get class HGSETGET.

1 Download

Updated 18 Mar 2011

View Version History

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

The HGSETGETPLUS class allows the user to:

* Implement a handle class with a get/set interface.
* Define validation criteria for properties that are checked when the
method SET is called.
* Display those criteria for a given property or all the properties.
* Set defaults for the properties.
* Allow a variety of input types in a consistent manner.

>> h = hgsetgetplusTemplate

h =

hgsetgetplusTemplate handle

length: 0
unit: 'm'

Methods, Events, Superclasses

>> set(h)
length: 'double -and- scalar'
unit: '[ {m} | cm ]'

>> set(h,'unit','kg')
??? Error using ==> setOneProperty
Expected kg to match one of these strings:

m, cm

The input, 'kg', did not match any of the valid strings.

I would like to thank Jiro Doke for some ideas that got me started and for encouraging me to submit this.

Cite As

Andrew Newell (2021). HandleGraphicsSetGet class (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

Andrew Newell

Martin, sorry for such a slow reply - I don't recall ever being notified of your comment.

I don't consider this behavior a bug. It's part of the design. I chose to insist that the line

S = configureDefault(obj);

is always present in the configure method. In the template for the config method, this line is preceded by the comment

% Keep this line! The structure needs to be initialized.

It keeps the behavior simple and predictable.


Nice and useful submission, have just started using it.

However, a slight bug appeared when I defined a configuration without any choices, caused by line 21 in configToString.m:
if ~isempty(config.choices)

It could be changed to:
if isfield(config,'choices') && ~isempty(config.choices)

Eric Johnson

This is an excellent submission. My favorite feature is the enumeration of allowable property values for an object. As the reviewer above commented, this is well organized and documented.


Professional work. Clear documentation and examples. I also appreciate the unit test provided, which adds greatly to my confidence in this work.

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!