table variable name based on array

11 ビュー (過去 30 日間)
Azura Hashim
Azura Hashim 2016 年 7 月 29 日
コメント済み: Azura Hashim 2016 年 7 月 30 日
Hi, is it possible to assign table variable name based on strings in an array. For example:
colnames={'a' 'b'};
a=[1;2];
b=[3;4];
c=table();
c.colnames{1}=a;
c.colnames{2}=b;
Thank you.

採用された回答

James Tursa
James Tursa 2016 年 7 月 29 日
Do you mean like this:
c.(colnames{1}) = a;
c.(colnames{2}) = b;
  1 件のコメント
Azura Hashim
Azura Hashim 2016 年 7 月 30 日
Works perfectly thanks.

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2016 年 7 月 29 日
Set the VariableNames of the table when you create it.
colnames = {'a' 'b'};
a = [1;2];
b = [3;4];
c = table(a, b, 'VariableNames', colnames)
Or change them later by assigning to the VariableNames property of the table.
newnames = {'Alice', 'Bob'};
c.Properties.VariableNames = newnames
  1 件のコメント
Azura Hashim
Azura Hashim 2016 年 7 月 30 日
This works too thanks.

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

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by