How to access data in structures?
Mostrar comentarios más antiguos
I'm currently learning how to use structures in MATLAB and I'm finding it a little more confusing than cells and other regular arrays. I'm confused on how to call data stored in specific fields of a structure. I understand the format is "nameofstructure"."nameoffield", but I'm struggling with how to get the data I need from the structure without knowing the name of the fields. Say I had a structure with 2 fields, how would I go about getting the infomation from either one without knowing the name of the field? I tried pulling the names of the fields in a function and using them like so
fieldnames = fieldnames(structure)
fieldInedd = fieldnames(2)
informationfromthisfield = structure.fieldIneed
But this doesn't give a field that matlab can recognize and draw data from. Could anyone help?
1 comentario
Stephen23
el 17 de Oct. de 2020
To access the structure fieldname dynamically you need the syntax given here:
and to access the contents of the cell array returned by fieldnames you need to use curly braces:
Respuesta aceptada
Más respuestas (0)
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!