how can I use the function "table" in a loop when the number of input variables changes ?

1 回表示 (過去 30 日間)
Sim
Sim 2021 年 12 月 16 日
コメント済み: Sim 2021 年 12 月 16 日
Hi, how can I use the function "table" in a loop when the number of input variables var1,...,varN, in T = table(var1,...,varN) changes ?
For example, I have something similar, where I have to specify the number of columns of my matrix A to create a table:
A = [ 4 0 0
56 6 8
164 18 40
159 13 139];
T = table(A(:,1), A(:,2), A(:,3), 'VariableNames', {'col 1', 'col 2', 'col 3'})
However, my matrix A changes number of columns several times and I would like to find an automatic way to create tables in a loop without changing the number of table entries every time manually.. The best for me would be something like this:
for i = 1 : 5
T{i} = table(A{i}, 'VariableNames', VarNames_array)
end

採用された回答

Adam Danz
Adam Danz 2021 年 12 月 16 日
編集済み: Adam Danz 2021 年 12 月 16 日
T = array2table(A);
if you want to specify variable names "col#",
T = array2table(A), 'VariableNames', compose('col%d',1:size(A,2)));

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by