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
Syntax
FN=SGfieldnames([SG])
Input Parameter
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
- SG: This represents the Solid Geometry input, which can be a struct or a cell array of structs.
Output Results
- FN: A list of unique field names from the different SG structs and cells.
Algorithm Steps
- Initialize an empty array
FN to store field names.
- Iterate over each input argument using a loop from 1 to
nargin (number of input arguments).
- 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.
- Append the field names
FNi to the array FN.
- After processing all inputs, use
unique(FN, 'stable') to remove duplicate field names while preserving the order.
- 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