Importing formated time data into matlab
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Karen Hornsby
le 14 Fév 2012
Réponse apportée : Karam Jaradat
le 8 Août 2016
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 commentaires
Réponse acceptée
Kevin Holst
le 14 Fév 2012
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.
4 commentaires
Plus de réponses (2)
Kevin Holst
le 14 Fév 2012
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 commentaires
Kevin Holst
le 21 Fév 2012
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
le 8 Août 2016
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 commentaires
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!