필터 지우기
필터 지우기

How do I find the number of "struct" class in a structure array?

조회 수: 17 (최근 30일)
Ferd
Ferd 2019년 4월 7일
댓글: Ferd 2019년 4월 10일
Hi,
Is there a way to determine the number of "struct" names in the structure array?
This way I could elimate the previous non-struct variables created.
Thanks
Ferd
  댓글 수: 1
Clay Swackhamer
Clay Swackhamer 2019년 4월 8일
Hi Ferd maybe this will help. Let's say we defined a structure to hold a matrix, a cell, and a function. Could look like this:
s = struct %declare structure
s.someNumbers = [1, 2, 3] %add a matrix to the structure
s.someText = {'hello', 'world'} %add some text to the structure
s.someFunction = @(x) 2*x.^2 %add a function to the structure
Now, the function holds three different things. To get the names of these fields we can use
fieldNames = fieldnames(s)
To get the number of fields in the structure use
numFields = length(fieldNames)

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

채택된 답변

Walter Roberson
Walter Roberson 2019년 4월 8일
nnz(cellfun(@isstruct, struct2cell(YourStruct)))

추가 답변 (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