Migration from Matlab: translator and EEGlab

Hi,
I have to question that will help some colleagues/friends of mine to switch to python from matlab.

1

  • is there an automatic translator of code from matlab to
    python/numpy/matplotlib? I believe it would be very easy to implement
    due the similar syntax between the two. I could do something similar
    myself but first I better make sure it doesn’t exist yet.

2 - Is there a python/numpy/mpl equivalent of EEGlab? see: http://www.sccn.ucsd.edu/eeglab/

thanks
Giorgio

Hi,
I have to question that will help some colleagues/friends of mine to switch
to python from matlab.

1 - is there an automatic translator of code from matlab to
python/numpy/matplotlib? I believe it would be very easy to implement due
the similar syntax between the two. I could do something similar myself but
first I better make sure it doesn't exist yet.

None that I know of, and it probably wouldn't be easy. For one thing,
matlab uses parentheses for function calls and indexing, and it is
probably not always obvious which is which for a translator. One
could write something that got it mostly right and flagged
ambiguities, but I think you should expect that a human would have to
clean it up afterwards unless you attempt something ambitious and not
easy. Prove me wrong!

2 - Is there a python/numpy/mpl equivalent of EEGlab? see:
EEGLAB

There is pbrain, which is not and does not attempt to be an equivalent
of EEGLab, but it is an EEG viewer/analysis package in python, which
uses matplotlib (and VTK). It is specialized for spectral analysis,
but could be extended to do other things.

  http://neuroimaging.scipy.org/pbrain/

I first wrote an EEG analysis package in matlab, and after becoming
frustrated with the lack of good support for complex data structures,
networking, and programming paradigms, I jettisoned it for python and
wrote pbrain. I wrote matplotlib in support of the pbrain
application, so some of the work has already been done :slight_smile:

JDH

···

On 3/28/07, Giorgio F. Gilestro <gilestro@...287...> wrote:

Another thing that is maybe even more problematic is that matlab uses
call-by-value and value-based assignment while Python/Numpy uses
call-by-reference and reference-based assignment. So in matlab
     A = B;
     A(3,2) = 22;
will not modify B, but the equivalent numpy code
     A = B
     A[2,1] = 22
will modify both A and B. That means for a translator to create
efficient code it really needs to analyze if each copy created is ever
modified, and if so whether that matters. So I think you'd need to do
a full parsing of the matlab code. No regexp tricks are going to cut
it.

Another very tricky thing is that the indexing rules are very
different. Any time you see something like A(idx) in matlab you have
to really know what type of thing idx is exactly in order to translate
it properly. And then there's the issue with matlab code that calls
"SomeNonTrivialToolboxRoutine(x)". Even if it does exist in SciPy,
often the parameters are very different. And there's the one-based vs
zero-based thing. But that's probably the least of one's worries.

So there are a lot of challenges. But none of it seems impossible,
and there are some shortcuts you could take to get something that
would still be a useful first-pass, but require hand touch-up.

On the plus side, it's probably easier to translate from a
pass-by-value language to pass-by-reference than the other way around.

--bb

···

On 3/29/07, John Hunter <jdh2358@...287...> wrote:

On 3/28/07, Giorgio F. Gilestro <gilestro@...287...> wrote:
> Hi,
> I have to question that will help some colleagues/friends of mine to switch
> to python from matlab.
>
> 1 - is there an automatic translator of code from matlab to
> python/numpy/matplotlib? I believe it would be very easy to implement due
> the similar syntax between the two. I could do something similar myself but
> first I better make sure it doesn't exist yet.

None that I know of, and it probably wouldn't be easy. For one thing,
matlab uses parentheses for function calls and indexing, and it is
probably not always obvious which is which for a translator. One
could write something that got it mostly right and flagged
ambiguities, but I think you should expect that a human would have to
clean it up afterwards unless you attempt something ambitious and not
easy. Prove me wrong!