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.
Douglas Schwarz (2020). Parse property/value pairs and structures (https://www.mathworks.com/matlabcentral/fileexchange/22671-parse-property-value-pairs-and-structures), MATLAB Central File Exchange. Retrieved .
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) || 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!
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.