read in the .csv file with ddMMyyyy HHmm data
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Yue Liu
am 2 Jul. 2019
Beantwortet: Shameer Parmar
am 2 Jul. 2019
Hello,
I'm trying to read in a csv file which contains datetime data and normal numerical data, which looks like below:
010120180000 0.795
010120180010 0.734
010120180020 0.679
010120180030 0.629
010120180040 0.575
010120180050 0.519
010120180100 0.463
010120180110 0.417
......
the first column represents ddMMyyyyHHmm, and second the column is the water level. I want to read them into a datetime table so that I can easily plot the water level change with time. I tried the following code:
clc;
filename = fullfile('H:\','Filed work','QLD tide info','brisbane_bar_tide_2018.txt');
tidedata = readtable(filename);
but the readtable() function give me a table in which the datetime information been changed to numbers like:
10120180000.0000
10120180010.0000
10120180020.0000
10120180030.0000
10120180040.0000
10120180050.0000
Anyone knows what's the problem? Do I need to convert these numbers to other format?
Thanks!
0 Kommentare
Akzeptierte Antwort
Vismay Raj
am 2 Jul. 2019
you can read the file line by line as string https://www.mathworks.com/help/matlab/ref/fgets.html
once it is read then A(1:2) will give you the day and similiarly you can get all other detals . and use string to int conversion to get the integer value https://www.mathworks.com/help/matlab/matlab_prog/converting-from-string-to-numeric.html
0 Kommentare
Weitere Antworten (1)
Shameer Parmar
am 2 Jul. 2019
Hello Yue,
Here I have converted the input data to string format and then splitted it to DDMMYYY and HHMM and created output data, so that it will be easy for you to copy for your further operations..
Please see attached script and input file.. run it and see the results..
If you need any help let me know..
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!