How to extract number of fields and name of fields from a structure?

479 visualizzazioni (ultimi 30 giorni)
I have s.a = 1; s.b = 'abc'; s.c = []; How to extract the name of the fields: 'a', 'b', 'c'? And the number of fields: 3 (in this example)?

Risposte (2)

kintali narendra
kintali narendra il 16 Gen 2018
use length(fieldnames(structure)) to find the number of fields in a structure. In your case it is length(fieldnames(s)). To get the fieldnames use fieldnames(structure) in your case fieldnames(s) store the output in a different variable and call them.

Image Analyst
Image Analyst il 22 Ago 2016
Use the fieldnames() function.

Categorie

Scopri di più su Structures in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by