find the size of a structured array
142 次查看(过去 30 天)
显示 更早的评论
I have a structured array called 'Data' which is a 1x1 struct, within this structured array are Data.note1, Data.note2, Data.note3, Data.note4. How is it possible to find the number of fields in the structured array? Where if it was a cell you would use length(cell)! Doing this for the structured array returns 1 where it should be 4.
1 个评论
Stephen23
2022-12-13
编辑:Stephen23
2022-12-13
"Doing this for the structured array returns 1 where it should be 4."
No, it should return 1 because you have a scalar structure, you even wrote this yourself: "I have a structured array called 'Data' which is a 1x1 struct". A 1x1 array is scalar, i.e. has only one element, regardless of its class:
In contrast a structure array with four elements has ... four elements:
S = struct('X',{1,2,3,4}) % 1x4, not 1x1
length(S)
The size of a structure array is completely independent of how many fields it has.
采纳的回答
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!