.csv Date and Time assigned Data Import
显示 更早的评论
Hi dear Community,
I need to import csv data from Trials into MATLAB. The dataset is as follows:
2016/11/02 17:51:54,017;256,451812744141;0;0;0,130208298563957
I tried to achieve the import with csvread, but I guess, matlab cannot handle date and time in one cell?! Another problem may be, that the decimal delimiter symbol is ',' and not '.'. Actually, I don't need the date, I only need the time and the difference of the time between adjacent measurements as an additional column.
Help is very appreciated, thanks therefore in advance! Best Wishes, Georg
采纳的回答
更多回答(1 个)
dbmn
2016-11-4
Hi Georg,
if you already extracted the required string, it can easily be converted into a datetime variable using a custom inputformat (that is also capable of dealing with commas)
mytimevar = datetime('2016/11/02 17:51:54,017', 'InputFormat', 'yyyy/MM/DD HH:mm:ss,SSS');
if you still need to extract the string I may suggest stringsplit
2 个评论
Georg Söllinger
2016-11-4
编辑:Georg Söllinger
2016-11-4
dbmn
2016-11-4
I just checked with a csv-file that i created by copying your example line 5 times.
Here is what I found
- csvread gives you the error you specified (most likely due to the fact, that the file is not "real csv" due to the additional commas
- one solution is to use readtable
data = readtable('20161102_R05_1.csv');
- Another possibility with more control is to use textscan
fid = fopen('20161102_R05_1.csv','r');
data={};
while ~feof(fid)
data(end+1,:) = textscan(fid, '%s%s%s%s%s', 1, 'delimiter',';');
end
fclose(fid);
类别
在 帮助中心 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!