help-octave
[Top][All Lists]
Advanced

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

RE: Python script for saving in Octave format


From: Keith Goodman
Subject: RE: Python script for saving in Octave format
Date: Sat, 14 May 2005 10:16:06 -0700

Here's an example of saving data in python (using scipy) and reading
it in Octave:

address@hidden:~$ python
Python 2.3.5 (#2, May  4 2005, 08:51:39)
[GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from scipy import *
>>> A = array([[1,2],[3,4]])
>>> A
array([[1, 2],
       [3, 4]])
>>> B = {'A':A}
>>> B
{'A': array([[1, 2],
       [3, 4]])}
>>> io.savemat('octavefile',B)
>>>
address@hidden:~$ octave
>> load octavefile.mat
>> A
A =

  1  2
  3  4

>> exit
address@hidden:~$ file octavefile.mat
octavefile.mat: data

And here's an example that (sort of, because I'm new to python) goes
in the other direction:

address@hidden:~$ octave
>> A = randn(2,2)
A =

   1.18745   0.46797
  -1.62821  -0.15456

>> save -mat-binary pythonfile.mat A
>> exit
address@hidden:~$ python
Python 2.3.5 (#2, May  4 2005, 08:51:39)
[GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from scipy import *
>>> io.loadmat('pythonfile.mat')
{'A': array([[ 1.18745315,  0.46797031],
       [-1.62821282, -0.15456162]]), '__version__': '1.0',
'__header__': 'MATLAB 5.0 MAT-file, written by Octave 2.1.69,
2005-05-14 15:58:24 UTC'}
>>> A
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'A' is not defined
>>>



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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