help-octave
[Top][All Lists]
Advanced

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

Re: text and numbers


From: Karim Elaagouby
Subject: Re: text and numbers
Date: Thu, 18 Feb 1999 10:03:34 -0800

Daniel Heiserer wrote:

> Huaiyu Zhu wrote:
> >
> > What's the best way to input text and data from the same file?
> >
> > This does not work:
> >
> > data = [
> > 'name1' 12 34
> > 'name2' 56 78
> > ];
> >
> > I want to input a structure that has both text and numbers, and then
> > separate out submatrices.  Of course I can use perl and friends to
> > separate them into two files and input them separately, but that
> > introduces consistency issues.
> >
> > I remember asking this question about matlab once, but can't locate the
> > answer now.  Is octave behaving similarly to matlab in this regard?
> >
> > Thanks.
>
> 1)
> Try fscanf and friends.
> 2)
> The fastest way probably ist to do a
>
> fread;reshape according to "\n" extract the columns you want and do a
> eval or fscanf on
> it to get the numerical values if wanted.
> 3)
> For such things I NEVER go into octave or matlab.
> Perl is the fastest AND most convenient way to do that.
> Just include a perl script via "system" in a m-file which produces
> some files "/tmp/a.ascii, /tmp/b.ascii" and an additional m-file
> which says: "load /tmp/b.ascci;load /tmp/a.ascii"
> and so on.
>
> Example:
> #my m-perl files
> system("myperl.pl stuff");
> loader
>
> #loader
> load /tmp/b.ascci;load /tmp/a.ascii
>
> bye
>
> --
> Mit freundlichen Gruessen
>                                  Daniel Heiserer
> -----
> --------------------------------------------------------------
> Dipl.-Phys. Daniel Heiserer, BMW AG, Knorrstrasse 147, 80788 Muenchen
> Abteilung EK-20
> Tel.: 089-382-21187, Fax.: 089-382-42820
> mailto:address@hidden

I found that the fastest way to load such a file is to use
shell calls. For a string column:

col1 = system("cut -f 1 -d' ' file_name ");

and for data save the column to a file then "load" it, it's faster than
fscanf

example :

tmp_Fname  = [ 'col2.'  int2str(time) '.txt' ];   # make temp file that's
unlikely to conflict with any other one

system ([" cut -f 2 -d' ' file_name > " tmp_Fname ]);
eval ([" load " tmp_Fname ";"]);

your vector will be called col2
then remove the temp file

system(["rm " tmp_Fname ";"]);

Well, I am assuming you are using UNIX/LINUX


--
Karim Elaagouby
Information Systems Analyst
idealab!
130 W. Union St.
Pasadena, CA 91103
address@hidden
626/535-2779 Direct
626/585-6900 Reception
626/535-2701 fax





reply via email to

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