splitvars
Splits multi-column table variables into separate variables.
Category: Language Fundamentals > Data Types
Syntax
T2 = splitvars(T)
Splits every variable that has more than one column.
T2 = splitvars(T, vars)
Splits only the variables in vars.
T2 = splitvars(___, 'NewVariableNames', names)
Names the new variables.
Description
A table variable can hold a matrix whose columns belong together, such as coordinates. splitvars turns each column into its own variable, named after the original with a suffix (M_1, M_2, ...). mergevars does the opposite.
Input arguments
T- Table.
vars- Names or indices of the variables to split.
Output arguments
T2- Table with one variable per column of the split variables.
Example
T = table([1 2; 3 4], 'VariableNames', {'M'});
splitvars(T)
Output
ans = 2×2 table
M_1 M_2
___ ___
1 2
3 4