loading .mat file causes problem with whos
Jason Cartwright
cartwright.jm at gmail.com
Mon Jun 22 21:33:45 CDT 2009
Octave version 3.0.3 -- this is a precompiled binary
Type of machine, operating system, and version number:
OS Name Microsoft Windows XP Professional
Version 5.1.2600 Service Pack 3 Build 2600
System Manufacturer TOSHIBA
System Model Satellite A205
System Type X86-based PC
Processor x86 Family 6 Model 15 Stepping 13 GenuineIntel ~1595 Mhz
BIOS Version/Date Phoenix Technologies LTD 1.70, 11/6/2007
SMBIOS Version 2.4
Hardware Abstraction Layer Version = "5.1.2600.5574 (xpsp_sp3_qfe.080402-1256)"
Total Physical Memory 1,024.00 MB
Available Physical Memory 86.18 MB
Total Virtual Memory 2.00 GB
Available Virtual Memory 1.96 GB
Page File Space 2.38 GB
The problem is summarized as follows. When I load a .mat file, then I
try to see which variables the .mat file contained using whos. When I
run whos (or whos -variables) there is no output. Below I Illustrate
the problem
Using whos after .mat file has been loaded, assume the .mat file
contains variables a and b
> load 'matfile.mat'
> whos
>
I have noticed two things. One, that whos only works for me
sporadically. Two, if whos is working then invoking any sort of
octave bug (as opposed to user error e.g. calling a function with
incorrect args) then afterwards whos doesn't work.
If you do need to access variables from a .mat file but don't know the
variable names, such as to perform math with the variables, from a
.mat file I do have a work around. Unfortunately this, for me, may
also work sporadically due to other bugs. Basically you want to load
the .mat file into a structure and find out the names of all the
fields of the structure, these will be the variable names. Example
code follows
% assuming our file is called matfile.mat, and contains two variables
a and b (but we don't know that)
> S = load( 'matfile.mat' );
% get the field names which are also the variable names
> T = fieldnames( S );
% assuming some sporadic bug doesn't prevent correct functioning, get
the length of T
> length( T )
ans = 2
% now we know there are 2 variables in matfile.mat, and can find out their names
> T{ 1 } % outputs ans = 'a'
ans = 'a'
> T{ 2 } % outputs ans = 'b'
ans = 'b'
% we can now do math with the variables
Note in my case some other bug is preventing me from seeing the
fieldnames directly such as the correct operation of this code
> S = load( 'matfile.mat' );
> T = fieldnames( S )
T = 'a'
'b'
In summary, loading a .mat file is one action that invokes a bug.
Also on my system whos only works sporadically. However, the
invocation of this bug causes whos to function incorrectly ie with no
output. It is likely that invoking any other bug will cause the same
problem. However, if you need to know the names of variables from the
.mat file and neither whos nor the fieldnames outputs don't work, then
you may use the work around I've outlined above. The work around
seems to work without fail...so far (fingers crossed).
*footnote my variables are vectors with about 100k values
I hope this is able to help someone as I tried 2-3 different
techniques to recover the variable names before trying this, and
losing much sleep!
-Jason
More information about the Bug-octave
mailing list