parseSize - a function to aid OOP overloading of the size() method in user-defined classes. If the user provides the vector of dimensions of a hypothetical array object, parseSize will take care of the main input/output argument processing in a way that imitates the conventions of MATLAB's usual SIZE function.
EXAMPLE: consider the following class and notice how parseSize is used to implement the SIZE method in a single line,
end % properties
In the next several examples, we see that all of the same calling syntaxes as for the usual MATLAB size() function are now enabled for this class:
>> obj=myClass; obj.dimension=[3,5,4,1];
>> [m,n,p,q,r,s]=size(obj); [m,n,p,q,r,s]
3 5 4 1 1 1
>> [m,n]=size(obj); [m,n]
3 5 4
dimensions: A vector specifying the dimensions of a hypothetical array-like
object. Trailing ones are permitted.
numargsout: The number of requested outputs in a call to the class'
size method, e.g., for [m,n,p]=size(obj) a value of
numargsout=3 should be passed to parseSize.
dim: if the calling syntax to the class's size method is size(obj,i),
one would pass dim=i to parseSize.
argsout: a cell array to be passed as the varargout of the size method.
Matt J (2022). Overloading SIZE for Array-like User-Defined Objects (https://www.mathworks.com/matlabcentral/fileexchange/29691-overloading-size-for-array-like-user-defined-objects), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!