File Exchange

image thumbnail

Parse property/value pairs and structures

version 1.0 (2.05 KB) by

Parses property/value pairs just like Handle Graphics functions.

2 Downloads

Updated

View License

This function can be used to parse property/value pairs just like Handle Graphics functions which means that it can also handle structures with field names that are property names.

Comments and Ratings (5)

Douglas Schwarz

Matthew,
Adding error IDs is a great idea -- I'll do that. I don't know about providing for objects though. My intent is make it accept property/value pairs just like Handle Graphics functions so that includes structures. If HG functions accept objects then I'll add that, but I wouldn't think there'd be much call for it. Thanks for your comments!

This is an excellent submission, thank you!

I've made one minor extension in my version which allows this function to work with objects as well as structures. I haven't encountered any bugs because of it yet, but I can't guarantee that it's error free.

You could change the line:

elseif isstruct(arg)

to

elseif isstruct(arg) || isobject(arg)

For completeness/tidiness, you could also change the errors to include IDs (to allow user control of error management), so something like...

error('ParsePropVal:BadArgFormat', 'Properties must be specified by property/value pairs, structures, or objects.')

and

error('ParsePropVal:BadArgValue', 'Property ''%s'' does not exist or is ambiguous.', arg)

Arthur

Arthur (view profile)

Just what I needed!

John D'Errico

John D'Errico (view profile)

It took me a minute to see where this went beyond my own parse_pv_pairs, but it does offer an improvement over my code.

MATLAB Release
MATLAB 7.6 (R2008a)
Acknowledgements

Inspired by: parse_pv_pairs

Inspired: QR Code encoder

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video