help-octave
[Top][All Lists]
Advanced

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

Re: loading a file using a variable name


From: James Sherman Jr.
Subject: Re: loading a file using a variable name
Date: Thu, 12 Jul 2007 15:33:41 -0400

I'm not exactly sure what you mean here.  The function "load" is used to read variables that have been stored in a file (using "save" or other means), not to execute code.

If you want to save two variables such as var1 and var2 to a file called " var.dat",  then you could do something like:
> var1 = 100;
> var2 = 200;
> save("var.dat", "var1", "var2");
then to recover them,
> load("var.dat");

If on the other hand you wanted a script that declared var1 and var2 as above, you could put (like David said) the lines:
var1 = 100;
var2 = 200;
in a file called "var.m", then (assuming it is in your present directory or path) type
> var
at the command line.

Hope this helps.

On 7/12/07, address@hidden < address@hidden> wrote:
Hi,
filename = 'exp/fpdata.dat';
load(filename)   works, but only of filename is a data file,
not if it sets a couple of variables. In the latter case,
i cannot execute it if i can only refere to the name through
a variable, like just writing filename at the prompt.
Is there a way to do that?


> > datfile = 'xxx.dat'
> > load datfile
> >
> > And to load a file with variables set in it like:
> > var1=100;
> > var2=200;
> >
> > the load command gives an error. Command fopens runs,
> > but then the variables are no loaded, i do not konw how to do that.
> > I know executing the filename works, but if the filename is given
> > by a variable, then i do not know how to execute it.
> > Any idea?
> > Thanks in advance ...
>
> Hi,
> In this case you have to use the functional form of load. Example:
> datfile = 'mmm'
> datfile = mmm
> octave:2> load(datfile)
> octave:3> whos
>
> *** local user variables:
>
>   Prot Name            Size                     Bytes  Class
>   ==== ====            ====                     =====  =====
>    rw- __nargin__      1x1                          8  scalar
>    rwd datfile         1x3                          3  string
>    rwd mmm             9x2                        144  matrix
>
> Total is 22 elements using 155 bytes
>
> ...at least on the old GNU Octave, version 2.1.73.
> Cheers, Avraham
> --
> Please avoid sending to this address attachments in excess of 2MByte,
> or any Excell or Powerpoint attachments.
>
_______________________________________________
Help-octave mailing list
address@hidden
https://www.cae.wisc.edu/mailman/listinfo/help-octave


reply via email to

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