How to remove struct fields of a specific type
Mostrar comentarios más antiguos
I have a struct that contains data of various formats including further structs and instances of class objects. I would like to remove all fields that are of a specific type without needing to use their field names.
For example, the trackingScenario struct contains a varying number of "Tracker" objects that I would like to remove if desired. I have posted an example of the struct below.
struct with fields:
configData: [1×1 struct]
simulation: [1×1 struct]
Platform_1: [1×1 struct]
Platform_2: [1×1 struct]
Platform_3: [1×1 struct]
Platform_4: [1×1 struct]
Target_1: [1×1 struct]
Target_2: [1×1 struct]
new_test_tracker2: [1×1 Tracker]
The desired output would be the struct without the "Tracker" field. This has stumped me so thanks in advance!
Respuesta aceptada
Más respuestas (1)
sushma swaraj
el 7 de Jul. de 2023
0 votos
Hi,
You can use the rmfield function to remove a specified field from structure array.
Refer to this documentation :
Hope it helps!
Categorías
Más información sobre Structures en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!