Introduce columns in a table- Variables
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Patrick Brown
el 7 de Feb. de 2017
Comentada: Patrick Brown
el 8 de Feb. de 2017
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???
Respuesta aceptada
Steven Lord
el 8 de Feb. de 2017
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
Más respuestas (1)
the cyclist
el 7 de Feb. de 2017
% Create the table
x = rand(3,1);
tbl = table(x);
% Create the string that contains the variable name
varString = 'x';
% Access that variable, using the string
tbl(:,varString)
2 comentarios
the cyclist
el 8 de Feb. de 2017
This is also possible:
% Create the string that contains the variable name
varString = {'velocity'};
% Create the table with the name
x = rand(3,1);
tbl = table(x,'VariableName',varString);
Ver también
Categorías
Más información sobre Tables en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!