tags:

views:

237

answers:

5

I've used Matlab on and off before, but I need to develop a good understanding of it now, and the language I'm most familiar with is Python. Care to describe a Matlab language feature, idiom, best practice or philosophy as compared to Python?

There's a terrific amount of buzz for and resources pertaining to going the opposite direction, the matlab to (python + tools) conversion, but that's not the way I need to go. Which data structures to swap in, whether I should use classes, where Numpy intuition might go wrong, etc. would be appreciated.

Edit: rephrased, shortened question

+4  A: 

The documentation is one of the strong points of Matlab. If you need to get into Matlab, one of the best places to start is the "Getting Started" section. Some of it will be too basic for you, which is a lot better than if it was too advanced, but it will show you the most important aspects of the language. One of the things you may watch out for is that Matlab starts indexing at 1. For other aspects of Matlab programmers may need to be aware of, you may have a look at the answers to this question.

If you need Matlab for a specific task, the help provides lots of demos that should put you on the right path.

Jonas
The great help and other IDE features like the debugger are my favorite things about using Matlab. It's great that if I need to figure out how to something that I assume there's a built in function for, it's pretty easy to find.
Thomas
@Thomasballinger: I edited in a link to a somewhat related question about Matlab for programmers.
Jonas
Definitely, the Matlab documentation is really good.
domsterr
@Jonas: I've finally added contact info to my profile, so whenever the tutorial is in a state you wouldn't mind sharing, let me know. Thanks!
Thomas
A: 

I found this SciPy.org page helpful, even though it works better for the other direction, and doesn't directly address many core language features.

Along the same lines:

But none of these really explain to me the Matlab language and data structures, like a good book about the language, in a way that leverages my existing knowledge of python. (The question Jonas links to does though - check that out.)

Thomas
@Thomasballinger: I can email you the (short) tutorial I made eventually, if you're interested.
Jonas
That'd be great, thanks. If it's alright, I'll post some of the pointers that are most relevant for python to matlab here.
Thomas
+2  A: 

Thesaurus of Mathematical Languages, or MATLAB synonymous commands in Python/NumPy is great for looking up "translations" between common MATLAB tasks and NumPy.

I can't think of a particular tutorial. But one resource I've found really useful for picking up the ins and outs of MATLAB are the blogs:

In particular, Loren on the Art of MATLAB and Steve on Image Processing are two that I've learned a great deal from.

ars
These "translations" are very nice because they can work both ways, but a discussion of how Matlab works would be ideal.
Thomas
I see what you're getting at, unfortunately don't know of a particular book or tutorial, but updated the answer with some links you might find useful.
ars
+1  A: 
  1. Matlab has superb documentation. In a world where everyone complains about how bad documentation X is, I think Matlab's documentation contributes significantly to its popularity. Python's is good, too, but Matlab's just feels a bit more immediately accessible. You can tell that Mathworks put some care into it.

  2. In Matlab, the matrix is fundamental. If you do x = 3 in the workspace, you can then do matrix operations to x (as meaningless as that might be) such as transposition, inverse, eigendecomposition, etc. No casting is necessary. In Python/NumPy, you still need to convert arrays to matrices using scipy.matrix before doing matrix operations.

  3. I am not familiar with any explicit, popular Matlab philosophy analogous to Python's zen (i.e., import this). But many characteristics are similar: easy experimentation, fast development time, easy to debug and profile, high level, extensible.

  4. Matlab does not emphasize object orientation like Python. OO is still possible in Matlab (e.g., classes are supported), but I don't know many people who make use of it.

  5. I like to think in the following way: NumPy is like the Matlab core, SciPy is like the Matlab toolboxes, Matplotlib lets you plot like Matlab, and iPython is the Matlab workspace.

  6. Oh yeah... Matlab starts indexing with 1, not zero! This is a logical consequence of Matlab's fundamental idea that every numeric "thing" is a matrix, and in linear algebra, matrices are often indexed starting with 1.

Steve
A: 

You can't do indexing on function result directly;

from numpy import *
sin(array(range(10))*pi/10)[3]

doesn't work in Matlab; you need to save the result first:

x=sin(0:pi/10:pi)
x(3)

from Jonas's tutorial

Thomas