Filter löschen
Filter löschen

add column in table

92 Ansichten (letzte 30 Tage)
Luca Re
Luca Re am 11 Jul. 2023
Kommentiert: Luca Re am 12 Jul. 2023
T= struct2table(G);
c=1:length(T);
c=c';
i want to add c as new column of T!

Akzeptierte Antwort

Voss
Voss am 11 Jul. 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 Kommentare
Voss
Voss am 12 Jul. 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 am 12 Jul. 2023
thank

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by