%% Reorient Rows as Variables
% Create tables, and then reorient their rows to be variables in new tables.
% Load arrays of data from the patients.mat file. Create a table that contains the LastName, Gender, Age, Height, and Weight variables.

load patients
T1 = table(LastName,Gender,Age,Height,Weight);
head(T1,3)

%
% Reorient the rows of T1 to be the variables of the output table.

T2 = rows2vars(T1);

%
% Display the first four variables of T2. The first variable of T2 contains the names of the variables of T1. The remaining variables of T2 correspond to rows of T1. Since T1 did not have any row labels, the variables of T2 have default names, Var1 to VarN for N variables.

T2(:,1:4)

%
% Create a table with row names. If a table has row names, then rows2vars turns the row names into the names of variables.

T3 = table(Gender,Age,Height,Weight,'RowNames',LastName);
head(T3,3)

%
% Reorient the rows of T3.

T4 = rows2vars(T3);
T4(:,1:4)

% Copyright 2012 The MathWorks, Inc.