Effacer les filtres
Effacer les filtres

add column in table

92 vues (au cours des 30 derniers jours)
Luca Re
Luca Re le 11 Juil 2023
Commenté : Luca Re le 12 Juil 2023
T= struct2table(G);
c=1:length(T);
c=c';
i want to add c as new column of T!

Réponse acceptée

Voss
Voss le 11 Juil 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 commentaires
Voss
Voss le 12 Juil 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 le 12 Juil 2023
thank

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by