How to count field numbers of structure?

567 ビュー (過去 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 Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by