This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

struct2cell

Convert structure to cell array

Syntax

C = struct2cell(S)

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 = 3x1 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 array
    {'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