struct2cell

Converts the field values of a struct into a cell array.

Category: Language Fundamentals > Data Types

Syntax

C = struct2cell(s)

Returns the field values of s in a column of cells.

Description

The first dimension of the result follows the order of fieldnames(s), and the field names themselves are lost. Use fieldnames as well if you need to rebuild the struct later with cell2struct.

Input arguments

s
Struct or struct array.

Output arguments

C
Cell array. For a scalar struct with n fields it is n-by-1; for a struct array of size [r c] it is n-by-r-by-c.

Example

Scalar and array

s.a = 1; s.b = 'hi';
C = struct2cell(s)
size(struct2cell(struct('a', {1, 2})))
Output
C = 2×1 cell

    {[ 1]}
    {'hi'}
ans = 1×3

     1     1     2

See also

cell2struct fieldnames struct table2cell