How to access a table column using a string of the column name
251 次查看(过去 30 天)
显示 更早的评论
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
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!