Unstack Table Variables
Distribute values from one table variable to multiple table variables in the Live Editor
The Unstack Table Variables task lets you interactively unstack, or distribute, values in a table or timetable from one variable to multiple variables. The task automatically generates MATLAB® code for your live script.
Open the Task
To add the Unstack Table Variables task to a live script in the MATLAB Editor:
On the Live Editor tab, select Task > Unstack Table Variables.
In a code block in the script, type a relevant keyword, such as
table. Select Unstack Table Variables from the suggested command completions.
Unstack Table Variable Using Live Editor Task
This example shows how to unstack values from one variable in an input table and distribute them to multiple variables in an output table by using the Unstack Table Variables Live Editor task.
First, load a table that contains estimated influenza rates along the east coast of the United States. The table has a variable with flu rates and another variable indicating whether the rates are for the Northeast (
NE), Mid-Atlantic (
MidAtl), or Southeast (
SE) regions. (These data come from the Google Flu Trends project, since discontinued.)
Add the Unstack Table Variables task to your live script. Unstack the
Flu Rate variable so that the output table has variables named
SE, containing flu rates for those regions.
To group the data by month, select the
Group bymenu item below the
Monthvariable in the task.
To select the names of the output variables, click the radio button
Names of new table variablesabove the
Regionvariable. For each unique value in
Region, there is a corresponding variable in the output table.
To distribute values from the
Flu Ratevariable into the
SEvariables in the output, click the radio button
Values in new table variablesabove
Version HistoryIntroduced in R2020a
R2022a: Live Editor task does not run automatically if inputs have more than 1 million elements
Behavior changed in R2022a
This Live Editor task does not run automatically if the inputs have more than 1 million elements. In previous releases, the task always ran automatically for inputs of any size. If the inputs have a large number of elements, then the code generated by this task can take a noticeable amount of time to run (more than a few seconds).
When a task does not run automatically, the Autorun icon is disabled.
To run a task manually, on the Live Editor tab, click the Run Section button.
To enable running the section automatically, click the Autorun icon. The icon updates to display the enabled state.