Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Unstack data from single variable into multiple variables

`U = unstack(S,vars,ivar)`

`U = unstack(S,vars,ivar,Name,Value)`

```
[U,is] =
unstack(___)
```

converts
the table or timetable, `U`

= unstack(`S`

,`vars`

,`ivar`

)`S`

, to an equivalent table
or timetable, `U`

, that is unstacked. The `unstack`

function
unstacks a single variable in `S`

, specified by `vars`

,
into multiple variables in `U`

. In general, `U`

contains
more variables, but fewer rows, than `S`

.

An indicator variable in `S`

, specified by `ivar`

,
determines which variable in `U`

contains each value
in `var`

after it is unstacked. `unstack`

treats
the remaining variables in `S`

as grouping variables.
Each unique combination of values in the grouping variables identifies
a group of rows in `S`

that is unstacked into a single
row of `U`

.

You cannot unstack the row names of a table, or the row times
of a timetable, or specify either as the indicator variable. You can
specify row names or row times as constant variables with the `'ConstantVariables'`

argument.
Otherwise, the `unstack`

function treats them as
grouping variables.

converts
the table or timetable `U`

= unstack(`S`

,`vars`

,`ivar`

,`Name,Value`

)`S`

with additional options
specified by one or more `Name,Value`

pair arguments.

For example, you can specify how `unstack`

converts
variables from `S`

to variables in `U`

.

You can specify more than one data variable in

`S`

, and each variable becomes a set of unstacked data variables in`U`

. Use a vector of positive integers, a cell array containing multiple variable names, or a logical vector to specify`vars`

. The one indicator variable, specified by the input argument,`ivar`

, applies to all data variables specifies by`vars`

.

Was this topic helpful?