Syntax
S=stripfields(S,[Fieldnames])
Input Parameter
S : | | struct |
Fieldnames : | | List of field names as varargin |
Output Parameter
S : | | struct with removed fields |
Examples
S.A=1; S.B=2; S.C=3; S.D=4
stripfields(S,'A','C','B')
retainfields(S,'A','C','B')
Copyright 2019-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 algorithm is a MATLAB function named stripfields
that removes specified fields from a given structure. It is part of the SolidGeometry library, version 4.5, and was created by Tim Lueth in 2019.
Input Parameters
- S: A structure from which fields will be removed.
- Fieldnames: A list of field names provided as variable arguments (
varargin
) that specify which fields to remove from the structure.
Output
- S: The modified structure with the specified fields removed.
Algorithm Steps
- The function begins by determining the number of input arguments minus one, which represents the number of field names to be removed. This is stored in the variable
n
.
- The list of field names to be removed is stored in the variable
L
, which is derived from varargin
.
- A loop iterates over each field name in
L
:
- For each field name, the function checks if the field exists in the structure
S
using the isfield
function.
- If the field exists, it is removed from the structure
S
using the rmfield
function.
- The modified structure
S
is returned as the output.
Example
Consider a structure S
with fields A
, B
, C
, and D
:
S.A = 1; S.B = 2; S.C = 3; S.D = 4;
Calling stripfields(S, 'A', 'C', 'B')
will remove fields A
, C
, and B
from S
.
Algorithm explaination created using ChatGPT on 2025-08-18 22:54. (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