[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Parsing data files in Octave
From: |
David Bateman |
Subject: |
Re: Parsing data files in Octave |
Date: |
Tue, 31 Oct 2006 10:54:15 +0100 |
User-agent: |
Thunderbird 1.5.0.7 (X11/20060921) |
Jens Benecke wrote:
> Hello,
>
> I have a data file (SPICE log) that contains lines like these:
>
> ml_u: l_u=(-101.563dB,0)
> ml_o: l_o=(-101.002dB,0)
> ml_ges: l_ges=(-103.512dB,0)
> ml_rk: l_rk=(-142.705dB,0)
> ml_lk: l_lk=(-142.705dB,0)
> ml_mk: l_mk=(-107.185dB,0)
> mv_w: c_w=(-204.955dB,0)
> mr_s: r_s=(1.11031dB,0)
> mc4: c4=(-214.573dB,0)
> mc_w: c_w=(-204.955dB,0)
> mc_m: c_m=(-243.311dB,0)
> mc_l: c_l=(-215.746dB,0)
> mr_leitung: r_leitung=(7.68303dB,0)
> ml_leitung: l_leitung=(-199.576dB,0)
>
> Date: Tue Oct 31 09:43:22 2006
> Total elapsed time: 0.547 seconds.
>
>
> I would like to pipe these through an Octave script to have the dB values
> converted to "real" values. (i.e. realval = 10^(dBval/20) )
>
> I tried this script just to parse the values into variables as a first step
> and output it:
>
> fid = fopen("2_7_Param_Koppel_1teilig.log", "r");
> [matr, count] = fscanf(fid, "%s: %s=(%fdB,0)");
> matr
> fclose(fid);
>
> but all I get as output is
>
> warning: fopen: default open mode is now binary
> error: fscanf: invalid stream number = -1
>
> I also tried using "%s: %s=(%f%s,%i)" as a string to avoid having "dB"
> directly behind a variable declaration, to no effect.
>
>
> Can anybody help me debug this? I'm a bit lost ... =;)
>
>
> Thanks!
>
>
>
In octave 2.9.x
fid = fopen("test.txt","rt");
s = char(fread(fid)');
fclose(fid);
val_str = cell2mat(regexp(s,'([\-0-9\.]+)dB','tokens'));
val = str2double(val_str);
will give you a cell array of string values of the dB fields in val_str
and the numeric values in a vector val.. You can probably force the
regexp from octave-forge for 2.1.x to do something similar but I can't
test it.
D.
--
David Bateman address@hidden
Motorola Labs - Paris +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob)
91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax)
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary