MATLAB2Python
John Hunter
jdhunter at ace.bsd.uchicago.edu
Thu Apr 29 10:15:47 EDT 2004
>>>>> "Nick" == Nick Carter <nick.carter at roke.co.uk> writes:
Nick> Also look at Matplotlib for Matlab-like plotting:
Nick> http://matplotlib.sourceforge.net/
I find python + numeric/numarray + MLAb + scipy + matplotlib to be a
very workable replacement for matlab, but I'm biased :-)
Actually, I used to work all the time in matlab and wrote some fairly
complex applications in it. I just sort of hit the wall at some point
when I was trying to do networking, dbases, complex data structures,
and so on, in matlab. You *can* do it with the matlab + the built-in
JVM, but it's not easy, pretty, or fast.
At some point I found myself doing all my work in python and dumping
the results to data files for plotting in matlab. Since that is a
frustrating solution, I bit the bullet and wrote matplotlib, with the
goal of making plots that look as good as matlab's, and were as easy
to create.
Here is a little comparison of a script to generate some white noise,
convolve it with a low pass filter, and make two plots, one of the
time series and one of the power spectrum.
First in matlab
dt = 0.01;
t = [0:dt:10];
nse = randn(size(t));
r = exp(-t/0.05);
cnse = conv(nse, r)*dt;
cnse = cnse(1:length(t));
s = 0.1*sin(2*pi*t) + cnse;
figure(1)
plot(t,s)
figure(2)
psd(s, 512, 1/dt)
And then in matplotlib with a little help from numeric and friends
from matplotlib.matlab import *
dt = 0.01
t = arange(0,10,dt)
nse = randn(len(t))
r = exp(-t/0.05)
cnse = convolve(nse, r, mode=2)*dt
cnse = cnse[:len(t)]
s = 0.1*sin(2*pi*t) + cnse
figure(1)
plot(t,s)
figure(2)
psd(s, 512, 1/dt)
show()
Cheers,
John Hunter
More information about the Python-list
mailing list