Two different ways to create a struct have 2 different results
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Although it's documented in the struct help, I'm curious if someone can explain the reasoning. There are 2 ways to create a struct, (1) dynamically adding fields and assigning their values and (2) using struct('field1', value1, 'field2', value2, ... ).
(1):
code.metaInfo = getEmptyMetaInfo();
code.dataValid = false;
code.dataCodewords = cell(MAXROWS, MAXCOLUMNS);
The above results in:
code =
metaInfo: [1x1 struct]
dataValid: 0
dataCodewords: {90x30 cell}
(2):
code = struct('metaInfo', getEmptyMetaInfo(), 'dataValid', false, 'dataCodewords', cell(MAXROWS, MAXCOLUMNS));
But this results in...
code =
90x30 struct array with fields:
metaInfo
dataValid
dataCodewords
I would expect the result to be exactly the same (before reading struct's documentation). Why aren't they?
0 commentaires
Réponses (1)
Iain
le 22 Août 2013
I think it may be because structs are an alternative to cells and the chap who wrote the function thought it might make be sensible to distribute out the contents of cell arrays in such a fashion.
0 commentaires
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!