help-octave
[Top][All Lists]
Advanced

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

Re: Global variables are not restored with load()


From: Ben Abbott
Subject: Re: Global variables are not restored with load()
Date: Sat, 05 Jun 2010 19:37:18 -0400

On Jun 5, 2010, at 6:46 PM, Stefan Neumann wrote:
> 
>> -----------------------------------
>> octave:2> clear all
>> octave:3> global a
>> octave:4> a = 1;
>> octave:5> b = 2;
>> octave:6> save test.mat
>> octave:7> clear all
>> octave:8> load test.mat
>> octave:9> whos
>> Variables in the current scope:
>> 
>>  Attr Name        Size                     Bytes  Class
>>  ==== ====        ====                     =====  =====
>>    g  a           1x1                          8  double
>>       b           1x1                          8  double
>> 
>> Total is 2 elements using 16 bytes
>> -----------------------------------
>> 
>> Ben
> 
> Hi Ben,
> 
> 2010/6/5 Ben Abbott <address@hidden>
> On Jun 5, 2010, at 10:52 AM, Stefan Neumann wrote:
> 
> I did a quick test of the developers sources and octave-3.2.3. For each, the 
> global attribute was preserved. Perhaps an upgrade to a newer version will 
> resolve the problem for you?
> 
> the problem happens only when octave is restarted.
> If you just save/clear all/load then it works as you describe.
> It seems that some infos on variables, like "global", survive even a clear 
> all.
> 
> The global attribute is preserved by save(). It appears in the save-file like 
> this:
> 
> # ------------------------------------------------- #
> # Created by Octave 3.2.4, Sun Jun 06 00:41:11 2010 CEST <address@hidden>
> # name: a
> # type: global scalar
> 1
> # ------------------------------------------------- #
> 
> 
> But after restarting octave and load() it does not get restored, even though 
> it definitely has been saved. Just to make sure I retried just now:
> 
> # ------------------------------------------------- #
> octave:1> load a.dat
> octave:2> who
> Variables in the current scope:
> 
> ans
> 
> octave:3> a
> error: `a' undefined near line 3 column 1
> # ------------------------------------------------- #
> 
> See: no 'a'
> I use octave 3.2.4. Upgrading to 3.3.51 might be premature.
> 
> Stefan

For the developer's sources I get the global attribute is preserved.

octave:1> load test.mat
octave:2> whos
Variables in the current scope:

  Attr Name         Size                     Bytes  Class
  ==== ====         ====                     =====  ===== 
    g  a            1x1                          8  double
       b            1x1                          8  double

Total is 16 elements using 127 bytes

For 3.2.3, it is not.

octave-3.2.3:1> load test.mat
octave-3.2.3:2> whos
Variables in the current scope:

  Attr Name         Size                     Bytes  Class
  ==== ====         ====                     =====  ===== 
       b            1x1                          8  double

Total is 13 elements using 100 bytes

It appears that the older versions don't load the global variables.

Ben




reply via email to

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