Two different ways to create a struct have 2 different results

1 visualizzazione (ultimi 30 giorni)
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?

Risposte (1)

Iain
Iain il 22 Ago 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.

Categorie

Scopri di più su Structures in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by