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!