by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 4.4, Creation date: 2018-12-30, Last change: 2025-09-14
clarr=arrayof(cobj,[r,c])
cobj: | class object | |
r: | rows | |
c: | cols |
clarr: | array of class objects |
arrayof(polyshape,1,4)
arrayof(polyshape,2)
arrayof(polyshape,4,1)
This function, named arrayof, is designed to create an array of a specified class object in MATLAB. It is part of the SolidGeometry library and was introduced in version 4.4. The function is particularly useful for creating arrays of class objects, similar to how MATLAB's built-in functions like zeros, ones, and nan create arrays of numerical values.
polyshape.getfuncparams function, which extracts the first parameter from varargin or defaults to 1 if not provided.getfuncparams function, which extracts the second parameter from varargin or defaults to the value of r if not provided.repmat function, which replicates the class object cobj in a matrix of size r by c.Here are some examples of how to use the arrayof function:
arrayof(polyshape,1,4) - Creates a 1x4 array of polyshape objects.arrayof(polyshape,2) - Creates a 2x2 array of polyshape objects (since c defaults to r).arrayof(polyshape,4,1) - Creates a 4x1 array of polyshape objects.The function begins by determining the number of rows and columns for the array using the getfuncparams function. This function checks the varargin input to see if the user has specified these values. If not, it defaults to 1 for rows and the value of rows for columns. The repmat function is then used to create the array of the specified class object, with the desired dimensions.