SGfieldnames

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

collects all field names in different Solid Geometries

Description

This function is used to prepare struct arrays from cell arrays
A cell list of structs can only be transformed into a array of structs if all fields name exist in all cell elements.
Function SGfieldnamessearches for all field names.
Function SGaddfields adds the missing fields to all elements of a solid
Function SGcell2array converts the cell list into an array


See Also: , SGaddfields , SGcell2array

Example Illustration

 missing image of SGfieldnames(SG)

Syntax

FN=SGfieldnames([SG])

Input Parameter

SG: Solid Geometry

Output Parameter

FN: Names of fields of the different SG structs and cells

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)




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, SGfieldnames, is designed to collect all field names from different Solid Geometries (SG) provided as input. It processes both struct and cell array inputs to ensure that all field names are identified and returned as a unique list.

Input Parameters

Output Results

Algorithm Steps

  1. Initialize an empty array FN to store field names.
  2. Iterate over each input argument using a loop from 1 to nargin (number of input arguments).
  3. For each input SGi:
    • If SGi is a struct, retrieve its field names using fieldnames(SGi) and store them in FNi.
    • If SGi is a cell, recursively call SGfieldnames on its contents using SGfieldnames(SGi{:}) to get field names.
  4. Append the field names FNi to the array FN.
  5. After processing all inputs, use unique(FN, 'stable') to remove duplicate field names while preserving the order.
  6. Return the unique list of field names FN.
Algorithm explaination created using ChatGPT on 2025-08-19 07:05. (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