How to count field numbers of structure?

507 visualizaciones (últimos 30 días)
GyuSang
GyuSang el 16 de Oct. de 2015
Comentada: Vincent Hall el 6 de Sept. de 2019
Please let me know how to count field numbers of structure as below.
Structure.A = zeros(10); Structure.B = zeros(10); Structure.C = zeros(10);
there are 3 fields in structure, and I want to know number '3'.
  2 comentarios
Stephen23
Stephen23 el 16 de Oct. de 2015
Use this:
numel(fieldnames(Structure))
Vincent Hall
Vincent Hall el 6 de Sept. de 2019
Thanks Stephen Cobeldick, that works nicely.

Iniciar sesión para comentar.

Respuesta aceptada

KSSV
KSSV el 16 de Oct. de 2015
length(fieldnames(Structure))
  3 comentarios
GyuSang
GyuSang el 16 de Oct. de 2015
Thank you for your answer.
Jan
Jan el 16 de Oct. de 2015
@Jos: I've seen many bugs caused by using length too sloppy. In the current case fieldnames replies a cell vector, such that length is trustworthy here.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by