SGcell2array

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - SG/Solids
Introduced first in SolidGeometry 5.0, Creation date: 2020-09-06, Last change: 2025-09-14

converts a cell list of solids into a struct array of solids

Description

this function was more or less written since is was at this time unclear wether a cell list - that can make some trouble as varargin - is better or worse than a struct array
In contrast to a cell list, an array of struct requires the same struct fields for all structs

See Also: isSG

Example Illustration

 missing image of SGcell2array(SGC)

Syntax

SGN=SGcell2array([SGC])

Input Parameter

SGC: Cell of Solids

Output Parameter

SGN: Array of Solids - requires the same struct fields for all structs

Examples


loadweb JACO_robot.mat; A=JACO
B=SGbox
loadweb ADAM_C.mat; C=ADAM_C
FN=SGfieldnames({A,B,C})
SGaddfields({A,B,C},FN)
SGcell2array({{A,B,C}})




Copyright 2020-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, SGcell2array, is designed to convert a cell list of solids into a struct array of solids. It is part of the SolidGeometry library and was introduced to address the issue of whether a cell list or a struct array is more efficient for handling solids.

Input Parameters

Output Results

Algorithm Steps

  1. The function begins by capturing the input arguments into the variable SG.
  2. It retrieves the field names of the solids using the function SGfieldnames and stores them in FN.
  3. It then ensures that all solids have the same fields by calling SGaddfields with the solids and the field names.
  4. The number of input arguments is stored in na.
  5. An empty array SGN is initialized to store the resulting struct array of solids.
  6. The function iterates over each input argument:
  7. If no output is requested (nargout==0), the function visualizes the solids using SGfigure and SGTplotalpha.

Example Usage

The function can be used as follows:

loadweb JACO_robot.mat; A=JACO
B=SGbox
loadweb ADAM_C.mat; C=ADAM_C
FN=SGfieldnames({A,B,C})
SGaddfields({A,B,C},FN)
SGcell2array({{A,B,C}})

This example demonstrates loading solid objects, ensuring they have consistent fields, and converting them into a struct array.

Algorithm explaination created using ChatGPT on 2025-08-19 07:39. (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