MATLAB: Introduce columns in a table- Variables

table

Hi, I want to introduce columns in a table, then I write Table.a but a is a variable string and I want that the column has the name of this string how I can do that???

Best Answer

This is possible using a slight variation of the cyclist's initial approach.
% Sample data
A = magic(4);
% Create the table to which you want to add data
T = array2table(A, 'VariableNames', {'first', 'second', 'third', 'fourth'})
% Define the new variable and the data it should contain
newvariable = 'fifth';
x = [20; 17; 8; 2];
% Add the new variable to the table T
T.(newvariable) = x