Filter löschen
Filter löschen

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

466 Ansichten (letzte 30 Tage)
Mr M.
Mr M. am 22 Aug. 2016
Beantwortet: kintali narendra am 16 Jan. 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)?

Antworten (2)

kintali narendra
kintali narendra am 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 am 22 Aug. 2016
Use the fieldnames() function.

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by