help-octave
[Top][All Lists]
Advanced

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

Re: Reading tab-delimited ASCII files


From: kensmith
Subject: Re: Reading tab-delimited ASCII files
Date: Wed, 8 Aug 2007 07:31:26 -0700
User-agent: KMail/1.9.1

I think it is better to stay all within octave for this job.  octave 
isn't advertized as a way to process strings but it has enough tools 
for this sort of problem.  Making the extra disk file will slow things 
down enough that looping in octave shouldn't be any slower.



On Tuesday 07 August 2007 21:14, address@hidden wrote:
>   Hi all,
>
> maybe you can strip your data from the first 2 columns, substitute
> the N/A for NaN, save the result in a temp file and load that temp
> file?  As in the following code (for unix system)
>
>    ## Make data octave-readable
>    system (["perl -w -p -e 's/.*?\t.*?\t//; s|N/A||ig' <
> ",your_file_name, "> /tmp/some_safe_temp_file_name.txt"]);
>
>    ## Read it
>    your_data = load ("/tmp/some_safe_temp_file_name.txt")
>
>    ## let's be good and clean up
>    unlink ("/tmp/some_safe_temp_file_name.txt")
>
> (in production code, you'd want to use a temp name returned by
> tmpnam()).
>
>   Hth,
>
>   Etienne
>
>
> On Tue, August 7, 2007 13:11, James Sherman Jr. wrote:
> # Well, I can't attest to it being any faster, but something like
> # [v1, v2, v3, v4] = fscanf(fid, "%s%s%s%s", 'Inf')
> # Would give you an already parsed line with v1 being the first
> column in the # line, and so on.  v[1-4] are still strings though, so
> doing some simple # strcmp calls to check if the string is a N/A or
> an actually number to sort # out the rest.
> #
> # Hope this helps.
> #
> # James Sherman
> #
> # On 8/7/07, Matthias Brennwald <address@hidden> wrote:
> #>
> #> Dear all
> #>
> #> I've got some ASCII file containing data which I'd like to read
> into #> Octave. The ASCII files contain several lines and columns.
> The columns #> are separated by tabs. The first column contains
> strings or variable #> width (parameter names), the remaining columns
> contain mostly numbers #> and some NaN values (e.g. 'N/A'). As an
> example, a file might look like #> this:
> #>
> #> K_G     1E-2    N/A     0.1
> #> KD_FIN  2       1.9     1.8
> #> KD_COA  0.2     0.02    1.2E-2
> #> T_LI    9.3244  8.233   N/A
> #>
> #> I tried using fscanf to read the data from the files, but I don't
> #> understand how to use the template parameter to specify the data
> format. #> I ended up reading line by line with fgetl and then
> analyzing each line #> seperately. This works, but it's slow. I
> believe that the fscanf #> function would be much faster. Can anyone
> give me an example of how to #> efficiently read ASCII files, e.g.
> the one above?
> #>
> #> Matthias
> #> _______________________________________________
> #> Help-octave mailing list
> #> address@hidden
> #> https://www.cae.wisc.edu/mailman/listinfo/help-octave
> #>
> # _______________________________________________
> # Help-octave mailing list
> # address@hidden
> # https://www.cae.wisc.edu/mailman/listinfo/help-octave
> #

-- 
address@hidden


reply via email to

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