How do I find the number of "struct" class in a structure array?
20 次查看(过去 30 天)
显示 更早的评论
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
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)
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!