help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem reading file with time-stamps


From: BVBA NuKey Music
Subject: Re: problem reading file with time-stamps
Date: Tue, 13 Dec 2011 14:24:43 +0100

OK, I installed octave-io but I'm still facing problems:
octave:5> A=textread("timestamps.txt", "%d", "delimiter", " ");
error: Unknown property delimiter.
error: Invalid argument specified

So I removed the word "delimiter" which gave me:
octave:7> A=textread("timestamps.txt", "%d", " ")
A =

   3.6074e-313
   3.6074e-313
   3.6074e-313

octave:8> A=textread("timestamps.txt", "%s", " ")
A =

{
  [1,1] = Dec-13-09:46:45
  [2,1] = Dec-13-09:47:12
  [3,1] = Dec-13-09:47:39
}


But how can I get my data in a matrix?

thanks in advance
nukey



2011/12/13 Ben Abbott <address@hidden>

On Dec 13, 2011, at 7:39 AM, BVBA NuKey Music wrote:

> 2011/12/13 Joanna Cheng <address@hidden>
>> On Tue, Dec 13, 2011 at 7:51 PM, BVBA NuKey Music <address@hidden> wrote:
>> > I'm trying to read a file with four columns which has timestamps in the
>> > first column:
>> >
>> > The data is available in the file in the following format:
>> > Dec-13-09:46:45 21.4 +4.76442190E-01 8.135530E-06 1.553691E+00
>> > Dec-13-09:47:12 21.4 +4.76439120E-01 8.135839E-06 1.553726E+00
>> > Dec-13-09:47:39 21.4 +4.76427260E-01 8.136261E-06 1.553853E+00
>> >
>> > first field is a timestamp then a space followed by a temperature then a
>> > space ...
>> >
>> > As you can see here below, octave doesn't accept the file because of the
>> > timestamps,
>> > can anyone here help me solve this problem?
>> >
>> > octave:1> y=load('x7r0.7vac0vdc.dat');
>> > error: load: failed to read matrix from file `x7r0.7vac0vdc.dat'
>> > error: evaluating assignment _expression_ near line 1, column 2
>>
>>
>> I actually wrote a bit of code to do this with csv files. See here:
>> http://www.octave.org/wiki/index.php?title=Tips_and_tricks#Load_Comma_Separated_Values_.28.2A.csv.29_files
>>
>> Sample output as below:
>>
>> octave:19> A=textread("timestamps.txt", "%d", "delimiter", " ");
>> octave:20> B=textread("timestamps.txt", "%s", "delimiter", " ");
>> octave:21> inds = isnan(A);
>> octave:22> B(!inds) = num2cell(A(!inds));
>> octave:23> B
>> B =
>> {
>>  [1,1] = Dec-13-09:46:45
>>  [2,1] =  21.400
>>  [3,1] =  0.47644
>>  [4,1] = 8.1355e-006
>>  [5,1] =  1.5537
>>  [6,1] = Dec-13-09:47:12
>>  [7,1] =  21.400
>>  [8,1] =  0.47644
>>  [9,1] = 8.1358e-006
>>  [10,1] =  1.5537
>>  [11,1] = Dec-13-09:47:39
>>  [12,1] =  21.400
>>  [13,1] =  0.47643
>>  [14,1] = 8.1363e-006
>>  [15,1] =  1.5539
>> }
>> octave:24> class(B)
>> ans = cell
>> octave:25> class(B{1})
>> ans = char
>> octave:26> class(B{2})
>> ans = double
>>
>> Hope that helps,
>> Joanna
>
> Thanks for replying but if I try out your code I get the following errors:
> octave:3> A=textread("timestamps.txt", "%d", "delimiter", " ")
> error: `textread' undefined near line 3 column 3
> error: evaluating assignment _expression_ near line 3, column 2
>
> and
>
> octave:3> B=textread("timestamps.txt", "%s", "delimiter", " ");
> error: `textread' undefined near line 3 column 3
> error: evaluating assignment _expression_ near line 3, column 2
>
> Any idea what is going wrong?
>
> thanks in advance
> nukey

(please reply below so that others arriving late can more easilly follow along)

I suspect you are using Octave 3.2 ? correct?

Joanna is likely using Octave 3.4.x or the developers sources (3.6.x).

If you are unable to upgrade your version of Octave, can you install the io package? You'll want to be sure that the version is < 1.0.13. The versions more recent that this do not include the textread() function (it was moved to Octave's core).

Ben



reply via email to

[Prev in Thread] Current Thread [Next in Thread]