Azzera filtri
Azzera filtri

add column in table

92 visualizzazioni (ultimi 30 giorni)
Luca Re
Luca Re il 11 Lug 2023
Commentato: Luca Re il 12 Lug 2023
T= struct2table(G);
c=1:length(T);
c=c';
i want to add c as new column of T!

Risposta accettata

Voss
Voss il 11 Lug 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 Commenti
Voss
Voss il 12 Lug 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 il 12 Lug 2023
thank

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Tables in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by