Importing formated time data into matlab
4 次查看(过去 30 天)
显示 更早的评论
Hi, I'm new to MatLab, but not completely new to programing, and I am ooking for a way to import data with a time stamp which formatted as hh:mm:ss AM/PM. Using the import wizard it doesn't recognise it as data but text. Is there a way of doing this or do I need to change the input file? Cheers, Karen
0 个评论
采纳的回答
Kevin Holst
2012-2-14
It all depends on what you're wanting to do with this data. You may be able to use the time just fine as a string. I'd suggest looking into using either datenum or datestr once the data is imported into matlab.
更多回答(2 个)
Kevin Holst
2012-2-14
Ok, so it looks like you won't be able to use matlabs fancy, easy data importer with this file, but if you will always be getting data in this format, you can create your own import function.
My suggestion, and this won't be pretty but it'll get the job done, is to do something like this:
fid = fopen('data.txt');
dateTimeStart = textscan(fgetl(fid),'Date/Time Start:%s','Delimiter','\t');
title = textscan(fgetl(fid),'Title:%s','Delimiter','\t');
comments = textscan(fgetl(fid),'Comments:%s','Delimiter','\t');
instrumentLabel = textscan(fgetl(fid),'Instrument Label:%s','Delimiter','\t');
fgetl(fid)
% etc collecting the data you want to keep in variables and using plain fgetl(fid) commands to skip a blank line
% for the channel size line, I'd probably use fgetl to get the whole line
% as a string and then cut off the first x characters, leaving just the
% numbers, and then you could use str2num to get those values into an array
% then we get to the real data.
textscan(fid,'%s %s %f %f %f %f %f %f %f %f %f %f') % this scans in all of your data into a 1x12 cell array, the first two columns are the time and AM/PM, the rest are numbers.
hope that helps!
3 个评论
Kevin Holst
2012-2-21
Karen,
Sorry for the delay, I was on vaca :) Unfortunately I'm away from my computer with Matlab and am unable to try this suggestion, but have you tried something like:
textscan(fid,'%s %s %f %f %f %f %f %f %f %f %f %f','Delimiter',{' ',','})
Karam Jaradat
2016-8-8
I suggest you to import the dates to excel first and change the format of the dates column to general, then copy the content and save it in txt file, then import this file to Matlab, it should work!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!