35861

creating graph from text file where axis X is date with millisecond precision and Y is value

Question:

I have text file like that:

10:00:15:956 0,0155260005803643 10:00:21:968 0,0155280030632315 10:00:21:968 0,0155270018379389 10:00:21:968 0,0155260006126463 10:00:22:069 0,0155239981620611 10:00:22:090 0,0155249993873537

First column is time with millisecond precision and second column is value. I need to draw graph where axis X is time and axis Y is value.

<ul><li>What function should I use to read file? dlmread, textscan, importdata?</li> <li>How to force matlab to recognize "time"? I can write time at any needed format (10:00:22:090 or 10.00.22.090 or anything else), but I need matlab to understand and process time labels correctly. For example difference between 10:00:22:090 and 10:00:23:090 is one second and exactly that interval should be use between these labels on axis X. I want to see "time" on axis X and I do not want to convert time to some "unreadable" int values or something like that (number of milliseconds elapsed from 10.00.00 for example.)</li> </ul>

Answer1:

You can have it in seconds and use datatics in plots. Note I have a quick fix to deal with comma in the second column. Probably you do not need it.

f = fopen('foo.txt'); data = textscan(f, '%f:%f:%f:%f %f,%f'); fclose(f); % hh:min:sec:millisec secvec = [60*60 60 1 1e-3]; x = [data{1:4}] * secvec'; flvec = [1 1e-16]; y = [data{5:6}] * flvec'; xindays = x / (24*60*60); plot(xindays, y, 'x'); datetick('x', 'HH:MM:SS');

Recommend

  • Finding the previous non-zero value from an date-ordered list
  • MySQL Compare prices
  • zoo objects and millisecond timestamps
  • Additional paypal fee on Woocommerce checkout page
  • How to make a matlab legend recognize multiple scatter plots?
  • Error building MEX-files (MATLAB 2012a) on Kubuntu '/usr/bin/ld: cannot find -lstdc++'
  • ZXING intent request code (identifying my intent)
  • MySql - get days remaining
  • data.table replicate rows after join?
  • Send multimedia commands
  • integration of function in modelica
  • Python function to read variable length blocks of data from file while open
  • Runtime.exec() gives Error: Could not find or load main class
  • Doctrine/Symfony entity generator and generating entity from one table
  • abstracting over a collection
  • Casting between Interfaces and Classes
  • jwtBearer bearer token with rc-1 update to ASP.Net 5
  • Enabling DTD support in Sql Server
  • Convert SQLite database to XML
  • Reading a file into a multidimensional array
  • Invalid object name 'dbo.Item'
  • Object and struct member access and address offset calculation
  • WPF Visiblity Binding to Boolean Expression with multiple Variables
  • Conversion from string “a” to type 'Boolean' is not valid
  • Installing Apache MyFaces 2 on WildFly 8.2.0
  • Hardware Accelerated Image Scaling in windows using C++
  • Magento Fatal error: Maximum execution error solution, on WAMP
  • Using jQuery closest() method with class selector
  • Email format validation in mvc3 view
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • Array.prototype.includes - not transformed with babel
  • How to add date and time under each post in guestbook in google app engine
  • Font Awesome Showing Box instead of Icons
  • Properly structure and highlight a GtkPopoverMenu using PyGObject
  • Arrays break string types in Julia
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • coudnt use logback because of log4j
  • Change div Background jquery
  • Is it possible to post an object from jquery to bottle.py?
  • Python/Django TangoWithDjango Models and Databases