How to count field numbers of structure?

조회 수: 484 (최근 30일)
GyuSang
GyuSang 2015년 10월 16일
댓글: Vincent Hall 2019년 9월 6일
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
Stephen23
Stephen23 2015년 10월 16일
Use this:
numel(fieldnames(Structure))
Vincent Hall
Vincent Hall 2019년 9월 6일
Thanks Stephen Cobeldick, that works nicely.

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
KSSV 2015년 10월 16일
length(fieldnames(Structure))
  댓글 수: 3
GyuSang
GyuSang 2015년 10월 16일
Thank you for your answer.
Jan
Jan 2015년 10월 16일
@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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by