add column in table
55 views (last 30 days)
Show older comments
T= struct2table(G);
c=1:length(T);
c=c';
i want to add c as new column of T!
0 Comments
Accepted Answer
Voss
on 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
7 Comments
Voss
on 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])
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!