MATLAB: Passing options from subclass constructor to superclass

classfunctionMATLAB

I really like the new "arguments" way to pass values, including optional values. However, one really nice feature of the (old?) varargin approach was that you could just pass the whole thing along. But with arguments, if I have a subclass that only needs a couple options and is happy to pass the rest to its superclass, I don't see a great way to do that. I've found that I need to specifically implement every option and pass them specifically. I'm probably missing something, but would love to learn what. Thanks! — David

Best Answer

Can't you just convert the options structure back to a cell array of name value pairs and use that to call the super class constructor? Using the attached function struct2pairs, this would be
function ourPicture = TakePicture(obj, aCIScene, intent, options)
arguments
obj;
aCIScene;
intent;
options.numHDRFrames = 3;
options.numBurstFrames = 3;
options.imageName char = '';
options.reRender (1,1) {islogical} = true;
end
...
varargin=struct2pairs(options);
ourPicture = TakePicture@ciCamera(obj, aCIScene, intent, varargin{:});;
end