a simpler way to add a string variable to a table
显示 更早的评论
I have a table T
Date City Visitors
----------------------
1/1/2020 New York 10
1/2/2020 New York 20
I want to add a variable 'state' that looks like
Date City Visitors State
----------------------
1/1/2020 New York 10 NY
1/2/2020 New York 20 NY
I did
state=strings(height(T),1)
then
state(:) = 'NY'
then I create a table and merged. But is there a simpler way?
2 个评论
KALYAN ACHARJYA
2020-12-19
编辑:KALYAN ACHARJYA
2020-12-19
T.newVar(:,1)=state;
Please ensure that state have same length as T, else you may have to use repmat
alpedhuez
2020-12-19
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!