loading data

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

loading data

David D. Clark
I would like to be able to use the input command to load a file name
without an extension, <filename>, use the strcat command to concatenate
the string with the appropriate extension, <ext> and then use the load
command to load the file <filename>.<ext>

e.g.

filename=input("Data File: ","s")
datafile=strcat(filename,".dat")
load datafile

However, when I run this, the following error occurs

octave:47> filename=input("Data File: ", "s")
Data File: m0812x
filename = m0812x
octave:48> datafile=strcat(filename,".dat")
datafile = m0812x.dat
octave:49> load datafile
error: load: couldn't open input file `datafile'
error: evaluating index expression near line 49, column 1

This indicates to me that load is looking at datafile as a literal, rather
than a variable.  Is there any way to get load to look at its argument as
a variable.  There is indeed a file named m0812x.dat.

Also, perhaps load does not like a string variable, in which case I need
to know what format to convert the string to.

Thanks for your help,

Dave Clark

David D. Clark
Graduate Research Assistant, Biophysics Group, P-21
MS D454
Los Alamos National Laboratory
Los Alamos, NM 87545
Phone (505)667-4147 Fax (505)665-4507


Reply | Threaded
Open this post in threaded view
|

Re: loading data

Mario Storti-4
>>>>> On Thu, 13 Aug 1998 12:21:25 -0600 (MDT),
>>>>>      "David D. Clark" <[hidden email]> said:

> I would like to be able to use the input command to load a file name
> without an extension, <filename>, use the strcat command to concatenate
> the string with the appropriate extension, <ext> and then use the load
> command to load the file <filename>.<ext>

> e.g.

> filename=input("Data File: ","s")
> datafile=strcat(filename,".dat")
> load datafile

> However, when I run this, the following error occurs

> octave:47> filename=input("Data File: ", "s")
> Data File: m0812x
> filename = m0812x
> octave:48> datafile=strcat(filename,".dat")
> datafile = m0812x.dat
> octave:49> load datafile
> error: load: couldn't open input file `datafile'
> error: evaluating index expression near line 49, column 1

You should write

octave> eval(["load " filename])

Hope this helps

Mario

%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%
Mario Alberto Storti                           | Fax: (54)(42) 55.09.44 |
Centro Internacional de Metodos Computacionales| Tel: (54)(42) 55.91.75 |
  en Ingenieria - CIMEC (INTEC/CONICET-UNL)    |........................|  
INTEC, Guemes 3450 - 3000 Santa Fe, Argentina                           |
Reply: [hidden email], http://venus.unl.edu.ar/gtm-eng.html |


Reply | Threaded
Open this post in threaded view
|

Re: loading data

John W. Eaton-6
On 13-Aug-1998, Mario Storti <[hidden email]> wrote:

| You should write
|
| octave> eval(["load " filename])
|
| Hope this helps

In recent versions of Octave, you can also avoid the call to eval by
writing

  load (filename);

So the original example

| > filename=input("Data File: ","s")
| > datafile=strcat(filename,".dat")
| > load datafile

could become just

  load (strcat (input ("Data File: ", "s"), ".dat"));
 
jwe