Borrar filtros
Borrar filtros

add column in table

92 visualizaciones (últimos 30 días)
Luca Re
Luca Re el 11 de Jul. de 2023
Comentada: Luca Re el 12 de Jul. de 2023
T= struct2table(G);
c=1:length(T);
c=c';
i want to add c as new column of T!

Respuesta aceptada

Voss
Voss el 11 de Jul. de 2023
G = struct('ones',{1 1 1 1},'twos',{2 2 2 2}); % for example
T= struct2table(G);
c=1:height(T); % use height
c=c';
T.new_column = c
T = 4×3 table
ones twos new_column ____ ____ __________ 1 2 1 1 2 2 1 2 3 1 2 4
  7 comentarios
Voss
Voss el 12 de Jul. de 2023
[Is it] possible [to] move c in the first column?
Yes, see below:
G = struct('ones',{1 1 1 1},'twos',{2 2 2 2}); % for example
T= struct2table(G);
c=1:height(T); % use height
c=c';
T.new_column = c;
T = T(:,[end 1:end-1])
T = 4×3 table
new_column ones twos __________ ____ ____ 1 1 2 2 1 2 3 1 2 4 1 2
Luca Re
Luca Re el 12 de Jul. de 2023
thank

Iniciar sesión para comentar.

Más respuestas (0)

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!

Translated by