Effacer les filtres
Effacer les filtres

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

466 vues (au cours des 30 derniers jours)
Mr M.
Mr M. le 22 Août 2016
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)?

Réponses (2)

kintali narendra
kintali narendra le 16 Jan 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 le 22 Août 2016
Use the fieldnames() function.

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by