www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/StackThreeVariablesintoOneExample.m

    %% Stack Three Variables into One  

%% 
% Create a table containing test scores from three separate tests. The
% table is in unstacked format.
Test1 = [93;57;87;89];
Test2 = [89;77;92;86];
Test3 = [95;62;89;91];

U = table(Test1,Test2,Test3) 

%%
% The table contains four rows and three variables.  

%% 
% Stack the test scores into a single variable. 
S = stack(U,1:3) 

%%
% |S| contains twelve rows and two variables. |S| is in stacked format.

%%
% The categorical variable, |Test1_Test2_Test3_Indicator|, identifies which
% test corresponds to the score in the stacked data variable, |Test1_Test2_Test3|.