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

398 visualizaciones (últimos 30 días)
Mr M.
Mr M. el 22 de Ag. de 2016
Respondida: kintali narendra el 16 de En. de 2018
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)?

Respuestas (2)

kintali narendra
kintali narendra el 16 de En. de 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 el 22 de Ag. de 2016
Use the fieldnames() function.

Categorías

Más información sobre Structures en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by