Why does "dir" function return an n by 1 struct?
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Pa342
el 8 de Abr. de 2018
Comentada: Pa342
el 12 de Abr. de 2018
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 comentarios
Respuesta aceptada
Matt J
el 8 de Abr. de 2018
Editada: Matt J
el 8 de Abr. de 2018
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!