MATLAB: How to manipulate data from a csv datafile containing date, time and number data

time series data analysis

This sounds intuitively easy but it has me puzzled. Columns 1 and 2 contain datetime formatted data, with column 3 double precision numerical. I can import the data using READTABLE with no apparent problem but subsequent manipulation continues to fall over. Is it best to split this into three separate (n x 1) arrays, or can I work with the data as one (n x 3) matrix? My routine is to read in the data, extract portions of the data (e.g. 600 rows) and then statistically analyse the values of the third column. The routine was working fine until I exceeded 24 hours of data, when it then ran into ambiguity due to ambiguous data type. I continue to run into a problem during subsequent code using DATEVEC, which produces an error message regarding data type, and using TABLE2ARRAY which also produces a data-type error. I am using R2016b. I am pretty new to Matlab and have attached a small sample input data. Cheers Bob

Best Answer

f = fopen('Input Data.csv');
c = textscan(f,'%s %s %f','delimiter',',');
fclose(f);
TT = timetable(datetime(strcat(c{1},c{2}),'In','dd-MMM-yyhh:mm:ss a'),c{3},'Va',{'datas'});