How to split only one column of a table (based on a space)?
10 次查看(过去 30 天)
显示 更早的评论
Hey!
I want to split only ONE column of a table I inserted into matlab. In this column, date and time (e.g., 22/06/2022 13:45:33) is seperated only by one space. I want to split this colum into two seperate ones, so one for date and one for time.
I appreciate any help! Thanks
0 个评论
采纳的回答
dpb
2022-5-3
If it's still in text form (string or cellstr), it's no problem
dt=split(tTable.DateString); % split the component pieces
tTable.Date=dt(:,1); % add Date column
tTable.Time=dt(:,2); % add Time column
Both are still whatever string type started out with.
Then it's trickier and splitting may not be the best idea after all -- in MATLAB datetime class, a date can exist with a presumed time of midnight but a time cannot exist without a corresponding date; there is no such thing as a standalone absolute time in this implementation.
You either turn time into a duration of some ilk or keep the date and simply change the display format to display the time portion alone.
A better and more complete answer could depend upon what the intent of the above is to accomplish -- it may not be necessary (probably isn't) to create the two variables anyway to perform whatever tasks are intended.
Another alternative could be to use a timetable instead where the date/time is inherent in the row structure and there are some specialized tools for common tasks that may well solve the problem.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!