Date problem in Octave

I am trying to plot some data using datetick function, first using data to parse some data. Here are some of the data I'm reading:

0, 6/23/2015 12:21:590 PM, 93.161, 95.911,94.515,95.917,        -5511.105,94.324,-1415.849,2.376,2.479
1, 6/23/2015 12:22:02 PM, 97.514, 96.068,94.727,96.138,-12500.000,94.540,-8094.912,2.386,2.479

      

I am trying the following code:

fileID = fopen('070915.csv');
C = textscan(fileID,'%f %s %f %f %f %f %f %f %f %f','Delimiter',',','headerLines', 9);
fclose(fileID);
formatIn = 'mm/dd/yyyy HH:MM:SS.FFF PM';
m = datenum(C{2},formatIn)
figure('Position',[0,0,1000,1000])
h1 = plot(m,C{5},'b');
datetick (formatIn);

      

and I am getting the following error:

error: datevec: DATE not parsed correctly with given format
error: called from
datevec at line 147 column 11
datenum at line 104 column 40
plotwithdate at line 18 column 3

      

I can get the frame rate to partially work by dividing the month / day / year from the time point and AM / PM using the following:

fileID = fopen('070915.csv');
C = textscan(fileID,'%f %s %s %s %f %f %f %f %f %f %f %f','Delimiter',', ','headerLines', 9);
fclose(fileID);
m = datenum(C{2},'mm/dd/yyyy')
n = datenum(C{3},'HH:MM:SS.FFF')
o = datenum(C{4},'AM')

      

which gives me the number 7xxxxx for each line for m, n and o. So the syntax looks ok until I try them all together.

+3


source to share


1 answer


Two problems with the code.

First, your format string doesn't match the number of columns. You need an extra one %f

there. Your code gives out:

C{2}
ans = 
{
   [1,1] = 6/23/2015 12:21:590 PM
   [2,1] = 1
   [3,1] = 2.479
}

      

So the first fix is ​​to add an extra one %f

to the text read format string:

C = textscan(fileID,'%f %s %f %f %f %f %f %f %f %f %f','Delimiter',',','headerLines', 9);

      

Which produces:

C{2}
ans = 
{
   [1,1] = 6/23/2015 12:21:590 PM
   [2,1] = 6/23/2015 12:22:02 PM
}

      



Now, the next thing you will notice is that it 12:21:590

is wrong. I assume it was just a typo in your example. But setting it on 12:21:59

still leaves problems.

You specified the format in fractions of a second, but your data does not include fractions of seconds. Octave will throw an error because of this. If you specify .FFF

, your data should include it, even if it's just like .0

.

Finally, Octave will still throw an error even if you add fractions of a second to your data. This is not your fault, however. It seems that an error occurs in the Octave, when both notation .FFF

and PM

used together. For example.:

>> datevec('06/01/2015 3:07:12 PM','mm/dd/yyyy HH:MM:SS PM')
ans =

   2015      6      1     15      7     12

>> datevec('06/01/2015 3:07:12.123','mm/dd/yyyy HH:MM:SS.FFF')
ans =

   2015.0000      6.0000      1.0000      3.0000      7.0000     12.1230

>> datevec('06/01/2015 3:07:12.123 PM','mm/dd/yyyy HH:MM:SS.FFF PM')
error: datevec: DATE not parsed correctly with given format
error: called from
    datevec at line 147 column 11

      

This issue is documented in the bug report for Octave. There is currently a revised version of the datevec.m function file attached to this bug report. According to the information on this page, the fixed feature will be part of Octave 4.0.1 after its release. At the same time, you can download and use the revised version to properly process your data.

Alternatively, if you have control over the original data format, you can either delete the pointer .FFF

(it looks like your data might not be needed anyway), or delete PM

and it will work.

Update: The above bug has been fixed and closed. Octave versions later than 4.0.1 should no longer have this problem.

+2


source







All Articles