MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
C{2,1}{1,2}

ans =
'two'

Refer to fields of a struct array with dot notation, and index into the array as described
for numeric and cell arrays. For example, C{2,2} returns a structure array, where
Field2 contains a 5-by-5 numeric array of fives. Access the element in the fifth row and
first column of that field using dot notation and smooth parentheses.

C{2,2}.Field2(5,1)

ans = 5

You can nest any number of cell and structure arrays. For example, add nested cells and
structures to C.

C{2,1}{2,2} = {pi, eps};
C{2,2}.Field3 = struct('NestedField1', rand(3), ...
'NestedField2', magic(4), ...
'NestedField3', {{'text'; 'more text'}} );

Access parts of the new data using curly braces, smooth parentheses, or dot notation.

copy_pi = C{2,1}{2,2}{1,1}

copy_pi = 3.1416

part_magic = C{2,2}.Field3.NestedField2(1:2,1:2)

part_magic = 2×2

16 2
5 11

nested_cell = C{2,2}.Field3.NestedField3{2,1}

nested_cell =
'more text'

12 Cell Arrays

Free download pdf