arrayof

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

returns an array of a class object

Description

Some class objects such as polyshape (2017b) are created by simply using the class name
Nevertheless arrays of such objects have to be created by the repmat function.
Typically the matlab convention is (,) for creating arrays for example
zeros(20,3) or ones (10,10,10) or nan (4)
This function support the same conventions for class objects

See Also: , cell2class , class2cell , array2cell

Example Illustration

 missing image of arrayof(cobj,r,c)

Syntax

clarr=arrayof(cobj,[r,c])

Input Parameter

cobj: class object
r: rows
c: cols

Output Parameter

clarr: array of class objects

Examples


arrayof(polyshape,1,4)
arrayof(polyshape,2)
arrayof(polyshape,4,1)




Copyright 2018-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

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.

Input Parameters

  • cobj: This is the class object that you want to create an array of. It can be any class, such as polyshape.
  • r: This parameter specifies the number of rows in the array. It is obtained using the getfuncparams function, which extracts the first parameter from varargin or defaults to 1 if not provided.
  • c: This parameter specifies the number of columns in the array. It is also obtained using the getfuncparams function, which extracts the second parameter from varargin or defaults to the value of r if not provided.

Output Results

  • clarr: This is the resulting array of class objects. It is created using the repmat function, which replicates the class object cobj in a matrix of size r by c.

Example Usage

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.

Function Details

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.

Algorithm explaination created using ChatGPT on 2025-08-19 00:33. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21