Why does "dir" function return an n by 1 struct?
18 次查看(过去 30 天)
显示 更早的评论
I am a novice at Matlab. I was reading about struct, and their size and that the size of a struct depends on the class of the value of the struct. If the struct values are not cells or if the cells are scalar, then the struct is 1 by 1. https://uk.mathworks.com/help/matlab/ref/struct.html
But when I look at the documentation for the 'dir' function: https://uk.mathworks.com/help/matlab/ref/dir.html?searchHighlight=dir&s_tid=doc_srchtitle
It says the class type in the struct are char, double and logical.
I looked at the class types documentation: https://uk.mathworks.com/help/matlab/matlab_prog/fundamental-matlab-classes.html
So these are their own class types, they are not cells, so why is the struct an n by 1 struct and not a scalar struct?
0 个评论
采纳的回答
Matt J
2018-4-8
编辑:Matt J
2018-4-8
If the struct values are not cells or if the cells are scalar, then the struct is 1 by 1.
The link you have cited applies specifically to inputs to the struct() command, when used to create MATLAB structure a array variables. The dir() command has its own rules.
The bottom line is, there is no connection between the dimensions of a struct array and the field data it contains. I could manually build a struct array of any dimensions regardless of whether its fields are cells, scalars, or whatever. Example:
>> s(2).cell={1,2,3,4}; s(1).scalar=5
s =
1×2 struct array with fields:
cell
scalar
更多回答(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!