rows2vars
Swaps the rows and variables of a table (transpose).
Category: Language Fundamentals > Data Types
Syntax
T2 = rows2vars(T)
Turns each row of T into a variable of T2.
Description
Where T.Properties.RowNames exists, the new variables take those names; otherwise they are called Var1, Var2, and so on. It is the table analogue of the transpose and is often used to prepare data for display.
Input arguments
T- Table whose variables can be concatenated (for example all numeric).
Output arguments
T2- Table with a first variable
OriginalVariableNamesholding the old variable names, followed by one variable per original row.
Example
T = table([1;2], [3;4], [5;6], 'VariableNames', {'A','B','C'});
rows2vars(T)
Output
ans = 3×3 table
OriginalVariableNames Var1 Var2
_____________________ ____ ____
{'A'} 1 2
{'B'} 3 4
{'C'} 5 6