Why does "dir" function return an n by 1 struct?
17 ビュー (過去 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!