1
votes

I have read the docs for accessing a cell array in

http://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-cell-array.html

It seems fairly straightforward; however, I appear to be lost as to access the 1X1 struct below.

I have an object (first_elem) which has class cell.

I wish to see the contents of the struct as I have just loaded in a MATLAB dataset for analysis.

>> first_elem

first_elem = 

    [1x1 struct]

>> class(first_elem)

ans =

cell

>> first_elem(1)

ans = 

    [1x1 struct]

>> class(first_elem(1))

ans =

cell

However, when I index the for the first element with (1), I get back another cell object instead of the 1x1 struct shown in [1x1 struct].

Am I missing something here?

Additional Context:

The initial file I loaded contained multiple datasets and looked like

>> display(train_small)

train_small = 

    train: {[1x1 struct]  [1x1 struct]  [1x1 struct]  [1x1 struct]  [1x1 struct]  [1x1 struct]  [1x1 struct]}

after loading.

I attempted to look at the contents of the first dataset with

first_elem = train_small.train(1)
1
It doesn't usually make sense to put structs inside cells. If all the structs have the same field names, use a struct array instead. - Matt J

1 Answers

2
votes

first_elem(1) returns a cell containing the first element only

first_elem{1} returns the first element