add column in table

18 ビュー (過去 30 日間)
shamal
shamal 2023 年 7 月 11 日
コメント済み: shamal 2023 年 7 月 12 日
T= struct2table(G);
c=1:length(T);
c=c';
i want to add c as new column of T!

採用された回答

Voss
Voss 2023 年 7 月 11 日
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 件のコメント
Voss
Voss 2023 年 7 月 12 日
[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
shamal
shamal 2023 年 7 月 12 日
thank

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by