%% Stack Table Variables Using Live Editor Task
% This example shows how to stack variables by using the Stack Table Variables Live Editor task. It takes values from multiple variables in an input table, and combines them into one variable in an output table.
% First, load a table that contains estimated influenza rates along the East Coast of the United States. The table has three variables with rates for the Northeast (NE), Mid-Atlantic (MidAtl), and Southeast (SE) regions. (These data come from the Google Flu Trends project, since discontinued.)

load fluByRegion

%
%
% Stack the flu rate data so that the flu rates from the NE, MidAtl, and SE variables are in one variable in the output table.
% Add the Stack Table Variables task to your live script.
% To copy values from the Month variable to rows of the output table, select Constant from the drop-down list above it in the task.
% To combine the values from the NE, MidAtl, and SE variables by stacking them into one variable of the output, select Stack for each variable.
% The name of the stacked variable in the output comes from combining the input variable names.
% The task also stacks the names of the input variables into a new variable, named NE_MidAtl_SE_Indicator. In this example, the names of regions are the names of variables in the input table. Those names become data values in a new variable that indicates the regions for the flu rate data.
%
%
% Give the variables of the output table more meaningful names. To rename table variables, use the renamevars function.

load fluRateOriginalNames
fluRate = renamevars(stackedTable,["NE_MidAtl_SE_Indicator" "NE_MidAtl_SE"],["Region" "Flu Rate"]);

%
% Copyright 2019-2020 The MathWorks, Inc.