2

I am attempting to organize a large amount of data into nested structures in MATLAB and I would like for each structure to contain a cell array but I get

A dot name structure assignment is illegal when the structure is empty. Use a subscript on the structure.

Example of code:

Year.Org1 = struct('Set1',{},'Set2',{});
Year.Org2 = struct('Set1',{},'Set2',{});

and then I want Set1/Set2/etc to be cell arrays of n-rows with column 1 str, column 2 str, column 3 value, and so on.

Any advice on initializing this structure and then accessing various parts would be greatly appreciated.

TroyHaskin
  • 8,361
  • 3
  • 22
  • 22
Ben K
  • 23
  • 2
  • Possible duplicate of [Matlab: adding value into initialized nested struct-cell](http://stackoverflow.com/questions/25998644/matlab-adding-value-into-initialized-nested-struct-cell) – TroyHaskin Oct 27 '15 at 19:32
  • @Troy Not exactly a duplicate I think the OP needs `{{}}` and not `{[]}`. – Ratbert Oct 27 '15 at 19:42

1 Answers1

1

With single curly braces the structure is initialized empty. You can achieve what you want by doubling the curly braces:

Year.Org1 = struct('Set1',{{}},'Set2',{{}});

Best,

Ratbert
  • 5,463
  • 2
  • 18
  • 37