# 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: [0 0.0635 0.1269 0.1904 0.2539 0.3173 0.3808 0.4443 0.5077 0.5712 0.6347 0.6981 0.7616 0.8251 0.8885 0.9520 1.0155 1.0789 1.1424 1.2059 1.2693 1.3328 1.3963 1.4597 1.5232 1.5867 1.6501 1.7136 1.7771 1.8405 1.9040 1.9675 2.0309 2.0944 ... ] y: [0 0.0634 0.1266 0.1893 0.2511 0.3120 0.3717 0.4298 0.4862 0.5406 0.5929 0.6428 0.6901 0.7346 0.7761 0.8146 0.8497 0.8815 0.9096 0.9341 0.9549 0.9718 0.9848 0.9938 0.9989 0.9999 0.9969 0.9898 0.9788 0.9638 0.9450 0.9224 0.8960 0.8660 ... ] title: 'y = sin(x)' ```

Convert `S` to a cell array.

`C = struct2cell(S)`
```C=3×1 cell array {[ 0 0.0635 0.1269 0.1904 0.2539 0.3173 0.3808 0.4443 0.5077 0.5712 0.6347 0.6981 0.7616 0.8251 0.8885 0.9520 1.0155 1.0789 1.1424 1.2059 1.2693 1.3328 1.3963 1.4597 1.5232 1.5867 1.6501 1.7136 1.7771 1.8405 1.9040 1.9675 2.0309 2.0944 2.1579 2.2213 2.2848 2.3483 2.4117 2.4752 2.5387 2.6021 2.6656 2.7291 2.7925 2.8560 2.9195 2.9829 3.0464 3.1099 3.1733 3.2368 3.3003 3.3637 3.4272 3.4907 3.5541 3.6176 3.6811 3.7445 3.8080 3.8715 3.9349 3.9984 4.0619 4.1253 4.1888 4.2523 4.3157 4.3792 4.4427 4.5061 4.5696 4.6331 4.6965 4.7600 4.8235 4.8869 4.9504 5.0139 5.0773 5.1408 5.2043 5.2677 5.3312 5.3947 5.4581 5.5216 5.5851 5.6485 5.7120 5.7755 5.8389 5.9024 5.9659 6.0293 6.0928 6.1563 6.2197 6.2832]} {[0 0.0634 0.1266 0.1893 0.2511 0.3120 0.3717 0.4298 0.4862 0.5406 0.5929 0.6428 0.6901 0.7346 0.7761 0.8146 0.8497 0.8815 0.9096 0.9341 0.9549 0.9718 0.9848 0.9938 0.9989 0.9999 0.9969 0.9898 0.9788 0.9638 0.9450 0.9224 0.8960 0.8660 0.8326 0.7958 0.7557 0.7127 0.6668 0.6182 0.5671 0.5137 0.4582 0.4009 0.3420 0.2817 0.2203 0.1580 0.0951 0.0317 -0.0317 -0.0951 -0.1580 -0.2203 -0.2817 -0.3420 -0.4009 -0.4582 -0.5137 -0.5671 -0.6182 -0.6668 -0.7127 -0.7557 -0.7958 -0.8326 -0.8660 -0.8960 -0.9224 -0.9450 -0.9638 -0.9788 -0.9898 -0.9969 -0.9999 -0.9989 -0.9938 -0.9848 -0.9718 -0.9549 -0.9341 -0.9096 -0.8815 -0.8497 -0.8146 -0.7761 -0.7346 -0.6901 -0.6428 -0.5929 -0.5406 -0.4862 -0.4298 -0.3717 -0.3120 -0.2511 -0.1893 -0.1266 -0.0634 -2.4493e-16]} {'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.

## Version History

Introduced before R2006a