3

I have imported a lot of timestamp in Matlab using this format: yyyy-mm-dd HH:MM:SS.FFF.

Now I have a vector like this one:

>> way(1:70,2)

ans =

   1.0e+05 *

   7.360197487028009
   7.360197487087731
   7.360197487264699
   7.360197487323611
   7.360197487519444
   7.360197487572569
   7.360197487750464
   7.360197487809028
   7.360197487988425
   7.360197488046759
   7.360197488225000
   7.360197488284375
   7.360197488463195
   7.360197488521990
   7.360197488700810
   7.360197488759027
   7.360197488937847
   7.360197488996875
   7.360197489175116
   7.360197489233681
   ...

I would like obtain a string in this format: yyyy-mm-dd HH:MM:SS. I have tried with this post but do not work (I have years from 2013 and more).

Apologize if the question is duplicate, but I have no found an answer in SX and in the web.

Thank you.

Community
  • 1
  • 1
Giacomo Alessandroni
  • 696
  • 1
  • 14
  • 28
  • 1
    1. How did you import the date? 2. Have you tried `datestr`? – nkjt Apr 22 '15 at 10:48
  • I have used Matlab tool for importing data into Matlab environment. I need to see the date/time only for the label in the plot. – Giacomo Alessandroni Apr 22 '15 at 10:56
  • 1
    If those are MATLAB datenums, you just need to use the inbuilt functions (there are plenty of examples in the help). For tick labels on a plot, use `datetick`. – nkjt Apr 22 '15 at 10:58

1 Answers1

2

maybe this?

datestr(way(1:70,2),'yyyy-mm-dd HH:MM:SS')

e.g. for the first value in the list:

datestr(1e5*7.360197487028009,'yyyy-mm-dd HH:MM:SS')
ans =

2015-02-24 17:58:07

HTH

Oliver Amundsen
  • 1,491
  • 2
  • 21
  • 40