How to convert datetime to datenum which date and time from different column?

12 vues (au cours des 30 derniers jours)
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);

Réponse acceptée

Ameer Hamza
Ameer Hamza le 9 Sep 2020
Modifié(e) : Ameer Hamza le 9 Sep 2020
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);

Plus de réponses (0)

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by