How to convert datetime to datenum which date and time from different column?
11 次查看(过去 30 天)
显示 更早的评论
Hi. anyone can solve this matter. I have a few columns which column1 (date) column2 (time) column3-15 (data)
I wanted to combine column1 and column2 so that I can convert it to datenum. This is example of data:
2019/10/07 20:15:00.000 5.349262952 103.258721787 2.1295 2 13 0.6876 0.6421 1.5800 -0.1096 0.0901 -0.5698 0.00 1.1
2019/10/07 20:15:01.000 5.349275362 103.258709080 5.0561 2 13 0.0145 0.0172 0.0356 -0.0006 -0.0111 -0.0106 0.00 1.1
2019/10/07 20:15:02.000 5.349286939 103.258719120 5.0214 2 13 0.0145 0.0172 0.0356 -0.0005 -0.0111 -0.0106 0.00 1.1
2019/10/07 20:15:03.000 5.349298684 103.258728601 5.1884 2 12 0.0145 0.0172 0.0358 0.0003 -0.0112 -0.0107 0.00 1.3
Below is the example of my coding:
clc;clear all; close all;
delim = ' '; % space delimited
% delim = '\t'; % tab delimited
% delim = ','; % comma delimited
%Input File
fid=fopen('E3D_KUAL_TPS.pos');
A = textscan(fid,'%s %s %f %f %f %f %f %f %f %f %f %f %f %f %f','HeaderLines',26); % read file;
date =string(A{1}); time =string(A{2});
str =([date time]);
dt = datetime(str,'InputFormat','yyyy/mm/dd hh:mm:ss.SSS');
dtnum = datenum(dt);
0 个评论
采纳的回答
Ameer Hamza
2020-9-9
编辑:Ameer Hamza
2020-9-9
Try this
% clc;clear all; close all;
delim = ' '; % space delimited
% delim = '\t'; % tab delimited
% delim = ','; % comma delimited
%Input File
fid=fopen('E3D_KUAL_TPS.pos');
A = textscan(fid,'%s %s %f %f %f %f %f %f %f %f %f %f %f %f %f','HeaderLines',26); % read file;
date =string(A{1});
time =string(A{2});
str = date + ' ' + time;
dt = datetime(str,'InputFormat','yyyy/MM/dd HH:mm:ss.SSS');
dtnum = datenum(dt);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!