Combine time related columns into timestamp for data in csv
Afficher commentaires plus anciens
Hi, I have a number of csv files where I would like change the way date and time data are recorded so that it is timestamped.
Time and data are currently stored as below:
year,month,day,hour,minute,second,data1,data2,data3
2009,1,1,0,0,0,2.9,12.1,7.1
I would like the CSV to read:
2009-01-01 00:00:00, 2.9, 12.1,7.1
I have tried the following script, which I appreciate has a few inefficiencies:
for y = 1:5
yStr = num2str(y);
C = csvread([folderPath,'c',yStr,'.csv']);
t = string(datestr(datetime(C(:,1),C(:,2),C(:,3),C(:,4),C(:,5),C(:,6)), 'yyyy-mm-dd HH:MM:SS'));
D = [t,C(:,7),C(:,8),C(:,9)];
csvfilename = 'd'+string(y)+'.csv';
csvwrite(csvfilename,D);
end
However the output I get has each individual letter in the string seperated by a comma.
How do I get the script to record the timestamp in my preferred format? The data stored in the variable 't' looks correct when viewed
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Spreadsheets dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
