struct2cell

Convert structure to cell array

Description

example

C = struct2cell(S) converts a structure into a cell array. The cell array C contains values copied from the fields of S.

The struct2cell function does not return field names. To return the field names in a cell array, use the fieldnames function.

Examples

collapse all

Create a structure.

S.x = linspace(0,2*pi);
S.y = sin(S.x);
S.title = 'y = sin(x)'
S = struct with fields:
        x: [1x100 double]
        y: [1x100 double]
    title: 'y = sin(x)'

Convert S to a cell array.

C = struct2cell(S)
C=3×1 cell array
    {1x100 double}
    {1x100 double}
    {'y = sin(x)'}

The cell array does not include field names. To return the field names in a cell array, use the fieldnames function. fieldnames and struct2cell return the field names and the values in the same order.

fields = fieldnames(S)
fields = 3x1 cell
    {'x'    }
    {'y'    }
    {'title'}

Input Arguments

collapse all

Input structure array. S can be a structure array of any size. If S is an m-by-n structure array with p fields, then C is a p-by-m-by-n cell array.

Extended Capabilities

Introduced before R2006a