Unstack Table Variables
Distribute values from one table variable to multiple table variables in the Live Editor
Since R2020a
Description
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.
More
Related Functions
Unstack Table Variables generates code that uses the
unstack
function.
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
unstack
. Select Unstack Table Variables from the suggested command completions.
Examples
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.)
load fluRate
fluRate
fluRate=18×3 table
Month Region Flu Rate
_____________ ______ ________
October-2005 NE 1.1902
October-2005 MidAtl 1.1865
October-2005 SE 1.273
November-2005 NE 1.361
November-2005 MidAtl 1.412
November-2005 SE 1.582
December-2005 NE 1.5003
December-2005 MidAtl 1.6043
December-2005 SE 1.8625
January-2006 NE 1.7772
January-2006 MidAtl 1.883
January-2006 SE 1.954
February-2006 NE 2.135
February-2006 MidAtl 2.1227
February-2006 SE 2.4803
March-2006 NE 2.2345
⋮
Add the Unstack Table Variables task to your live script. Unstack the Flu Rate
variable so that the output table has variables named NE
, MidAtl
, and SE
, containing flu rates for those regions.
To group the data by month, select the
Group by
menu item below theMonth
variable in the task.To select the names of the output variables, click the radio button
Names of new table variables
above theRegion
variable. For each unique value inRegion
, there is a corresponding variable in the output table.To distribute values from the
Flu Rate
variable into theNE
,MidAtl
, andSE
variables in the output, click the radio buttonValues in new table variables
aboveFlu Rate
.
unstackedTable=6×4 table
Month NE MidAtl SE
_____________ ______ ______ ______
October-2005 1.1902 1.1865 1.273
November-2005 1.361 1.412 1.582
December-2005 1.5003 1.6043 1.8625
January-2006 1.7772 1.883 1.954
February-2006 2.135 2.1227 2.4803
March-2006 2.2345 1.992 2.0203
Related Examples
Version History
Introduced in R2020aR2024a: Generate template code for custom aggregation function
When you select the Custom function
option for the
Aggregator for new table variable values method, you can generate
template code that can help you write your own custom aggregation function.
Select
Custom function
.Select
Local function
from the next menu.Click New to add a new local function to the script.
Select the name of the new local function from the next menu.
The live task generates template code and places it within the live script. To customize this code, edit it in the live script.
R2022a: Live Editor task does not run automatically if inputs have more than 1 million elements
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 indicator is disabled. You can either run the task manually when needed or choose to enable the task to run automatically.
See Also
Functions
Live Editor Tasks
Apps
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)