File Exchange

image thumbnail

Parse property/value pairs and structures

version (2.05 KB) by Douglas Schwarz
Parses property/value pairs just like Handle Graphics functions.


Updated 13 Jan 2009

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.

Cite As

Douglas Schwarz (2021). Parse property/value pairs and structures (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (5)

Douglas Schwarz

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!

Matthew Barrett

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)


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.')


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


Just what I needed!

Joshua Arnott

John D'Errico

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 Compatibility
Created with R2008a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: parse_pv_pairs

Inspired: QR Code encoder

Community Treasure Hunt

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

Start Hunting!