#!/usr/bin/env python from Numeric import * import os, sys # plot NumPy arrays in Matlab, if pymat is present: try: import pymat except: print "pymat module is not available..."; sys.exit(1) x = arrayrange(0,4*math.pi,0.1) m = pymat.open() pymat.put(m, 'x', x); pymat.eval(m, 'y = sin(x)') pymat.eval(m, 'plot(x,y)') y = pymat.get(m, 'y') import time; time.sleep(4) # wait before killing the plot... pymat.close(m) # compare sin(x) in Matlab and Python: print "Matlab: sin(%g)=%g. Python: sin(%g)=%g" % \ (x[1], sin(x[1]), x[1], y[1])
def close(self): pymat.close(self.H)
#!/usr/bin/python # Simple test file for the PyMat interface import pymat from Numeric import * x = array([1, 2, 3, 4, 5, 6]) H = pymat.open() pymat.put(H, 'x', x) pymat.eval(H, 'y = dct(x)') y = pymat.get(H, 'y') pymat.close(H) expect = asarray([8.573214099741124e+000, -4.162561795878958e+000, -1.785561006679121e-015, -4.082482904638622e-001, -1.638955159695808e-015, -8.007889124033019e-002]) err = sum((y-expect)*(y-expect)) print 'Norm of the error is:', err if err < 1e-15: print "(That's pretty small -- the test passes)" else: print "UMMM...THAT'S A BIT BIG! The test has failed."