How to access a table column using a string of the column name

203 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2017 年 11 月 16 日
回答済み: MathWorks Support Team 2017 年 12 月 20 日
If you have a table called table1 with column names X1, X2, X3, how can you access a column X1 with the variable v =  'X1'?

採用された回答

MathWorks Support Team
MathWorks Support Team 2017 年 11 月 16 日
This can be done using dynamic field indexing.
>> table1.('X1');
If you have a variable that contains the string.
>> v = 'X1';
>> table1.(v);
Note: This indexing also works for dataset arrays and structs.

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by