tags:

views:

4927

answers:

21

I've been recently asked to learn some MATLAB basics for a class.

What does make it so cool for researchers and people that works in university? I saw it's cool to work with matrices and plotting things... (things that can be done easily in Python using some libraries).

Writing a function or parsing a file is just painful. I'm still at the start, what am I missing?

In the "real" world, what should I think to use it for? When should it can do better than Python? For better I mean: easy way to write something performing.


UPDATE 1: One of the things I'd like to know the most is "Am I missing something?" :D

UPDATE 2: Thank you for your answers. My question is not about buy or not to buy MATLAB. The university has the possibility to give me a copy of an old version of MATLAB (MATLAB 5 I guess) for free, without breaking the license. I'm interested in its capabilities and if it deserves a deeper study (I won't need anything more than basic MATLAB in oder to pass the exam :P ) it will really be better than Python for a specific kind of task in the real world.

+9  A: 

MATLAB is great for doing array manipulation, doing specialized math functions, and for creating nice plots quick.

I'd probably only use it for large programs if I could use a lot of array/matrix manipulation.

You don't have to worry about the IDE as much as in more formal packages, so it's easier for students without a lot of programming experience to pick up.

Lance Roberts
What do you mean for "You don't have to worry about the IDE as much as in more formal packages"? I think I did not understand.
Andrea Ambu
You don't have to deal with linking, building, compiling etc (for the most part). I haven't played with Python yet, but I'm sure it's slightly more complicated than running the first matlab program.
Lance Roberts
The way it works at EE at my university, is that professors have the students use matlab to graph certain things. Then since they already have acquaintance with it, it's easier for them to step up to programming it.
Lance Roberts
I don't think it's simpler :\ You should at least try python as I'm doing with matlab :P
Andrea Ambu
If for EE you mean Electronic Engineering then the same is for me :D
Andrea Ambu
I've downloaded Python, just haven't got to it yet.
Lance Roberts
You don't have to deal with linking, building or compiling in Python either. In that respect Python and Matlab are the same.
Nathan Fellman
+6  A: 

The most likely reason that it's used so much in universities is that the mathematics faculty are used to it, understand it, and know how to incorporate it into their curriculum.

Adam Bellaire
+4  A: 

Between matplotlib+pylab and NumPy I don't think there's much actual difference between Matlab and python other than cultural inertia as suggested by @Adam Bellaire.

Aaron Maenpaa
Matlab's documentation is much much better than Python's. Matlab also comes with zillions of built-in functions that I have yet to see with Numpy or Pylab.
Nathan Fellman
Matlab has thousands of build-in functions but it also costs thousands of dollars. I see that Matlab and Python are converging with Matlab getting ideas from Python for its OOP and Python being always better in numerics.
Mikhail
+4  A: 

The main reason it is useful in industry is the plug-ins built on top of the core functionality. Almost all active Matlab development for the last few years has focused on these.

Unfortunately, you won't have much opportunity to use these in an academic environment.

John Mulder
+1  A: 

There is a free version called scilab but most universities require you to purchase matlab. It is nice for doing graphs and matrices.

http://www.scilab.org/

Jim C
If I'm not wrong numpy will come with scipy, the python porting of scilab...
Andrea Ambu
+2  A: 

First Mover Advantage. Matlab has been around since the late 1970s. Python came along more recently, and the libraries that make it suitable for Matlab type tasks came along even more recently. People are used to Matlab, so they use it.

Glomek
+7  A: 

MATLAB, as mentioned by others, is great at matrix manipulation, and was originally built as an extension of the well-known BLAS and LAPACK libraries used for linear algebra. It interfaces well with other languages like java, and is well favored by engineering and scientific companies for its well developed and documented libraries. From what I know of Python and NumPy, while they share many of the fundamental capabilities of MATLAB, they don't have the full breadth and depth of capabilities with their libraries.

Personally, I use MATLAB because that's what I learned in my internship, that's what I used in grad school, and that's what I used in my first job. I don't have anything against Python (or any other language). It's just what I'm used too.

Also, there is another free version in addition to scilab mentioned by @Jim C from gnu called Octave.

Scottie T
+4  A: 

One reason Matlab is popular with universities is the same reason a lot of things are popular with universities: there's a lot of professors familiar with it, and it's fairly robust.

I've spoken to a lot of folks who are especially interested in Matlab's nascent ability to tap into the GPU instead of working serially. Having used Python in grad school, I kind of wish I had the licks to work with Matlab in that case. It sure would make vector space calculations a breeze.

Robert Elwell
+3  A: 

I believe you have a very good point and it's one that has been raised in the company where I work. The company is limited in it's ability to apply matlab because of the licensing costs involved. One developer proved that Python was a very suitable replacement but it fell on ignorant ears because to the owners of those ears...

  1. No-one in the company knew Python although many of us wanted to use it.
  2. MatLab has a name, a company, and task force behind it to solve any problems.
  3. There were some (but not a lot) of legacy MatLab projects that would need to be re-written.

If it's worth £10,000 (??) it's gotta be worth it!!

I'm with you here. Python is a very good replacement for MatLab.

I should point out that I've been told the company uses maybe 5% to 10% of MatLabs capabilities and that is the basis for my agreement with the original poster

Derek Smyth
That's good to know, can you tell me what kind of thing does your company produce and what's matlab used for? Anyway this is just for personal interest, I don't think to be ever employed as matlab developer :P
Andrea Ambu
MATLAB is not THAT pricey. $2k/seat gets you the base version with no plug-ins.
Doresoom
+44  A: 

Adam is only partially right. Many, if not most, mathematicians will never touch it. If there is a computer tool used at all, it's going to be something like Mathematica or Maple. Engineering departments, on the other hand, often rely on it and there are definitely useful things for some applied mathematicians. It's also used heavily in industry in some areas.

Something you have to realize about MATLAB is that it started off as a wrapper on Fortran libraries for linear algebra. For a long time, it had an attitude that "all the world is an array of doubles (floats)". As a language, it has grown very organically, an there are some flaws that are very much baked in, if you look at it just as a programming language.

However, if you look at it as an environment for doing certain types of research in, it has some real strengths. It's about as good as it gets for doing floating point linear algebra. The notation is simple and powerful, the implementation fast and trusted. It is very good at generating plots and other interactive tasks. There are a large number of `toolboxes' with good code for particular tasks, that are affordable. There is a large community of users that share numerical codes (Python + NumPy has nothing in the same league, at least yet)

Python, warts and all, is a much better programming languags (as are many others). However, it's a decade or so behind in terms of the tools.

The key point is that the majority of people who use MATLAB are not programmers really, and don't want to be.

It's a lousy choice for a general programming language; it's quirky, slow for many tasks (you need to vectorize things to get efficient codes), and not easy to integrate with the outside world. On the other hand, for the things it is good at, it is very very good. Very few things compare. There's a company with reasonable support and who knows how many man-years put into it. This can matter in industry.

Strictly looking at your Python vs. MATLAB comparison, they are mostly different tools for different jobs. In the areas where they do overlap a bit, it's hard to say what the better route to go is (depends a lot on what you're trying to do). But mostly Python isn't all that good at MATLAB's core strengths, and vice versa.

simon
Matlab has a JIT compiler now that means you rarely have to vectorise code just for performance reasons these days.
Will Robertson
That's actually not true. The JIT helps, it's much better than nothing, but you still have to structure your code the right way. Vectorized code can be many orders of magnitude faster than naive matlab code. JIT might get you a factor of 2 or 5 back, in my experience.
simon
Vectorization is not as important as it once was. It still may help in some situations, but is no longer soemthing that you *have* to do.FYI: Vectorization is the idea of operating on a matrix or vector of data rather than a single scalar in a loop through the vector.
MatlabDoug
MatlabDoug: Oh I agree it's not as important as it once was, but it's still an issue, and sometimes a huge issue. And none of that speaks to the other design quirks of matlab as a general programming language (although I'll note that as of 2008a the object model is nicer)
simon
Vectorization is still very important. With the advent of SSE and wider registers it is needed to squeeze perf out of the processor. I can't comment on Matlab in general but to say vectorizing is not important is just wrong, especially in high scale software that is latency sensitive.
Steve
I totally disagree that JIT makes vectorized code useless. We use Matlab a lot to run experiments which take several weeks or months. Imagine if the program runs half as fast without vectorization we would need f.e. 2 months instead of 1 -> bye bye deadline !! (and half as fast is VERY optimistic).
George B.
+3  A: 

It's been some time since I've used Matlab, but from memory it does provide (albeit with extra plugins) the ability to generate source to allow you to realise your algorithm on a DSP.

Since python is a general purpose programming language there is no reason why you couldn't do everything in python that you can do in matlab. However, matlab does provide a number of other tools - eg. a very broad array of dsp features, a broad array of S and Z domain features.

All of these could be hand coded in python (since it's a general purpose language), but if all you're after is the results perhaps spending the money on Matlab is the cheaper option?

These features have also been tuned for performance. eg. The documentation for Numpy specifies that their Fourier transform is optimised for power of 2 point data sets. As I understand Matlab has been written to use the most efficient Fourier transform to suit the size of the data set, not just power of 2.

edit: Oh, and in Matlab you can produce some sensational looking plots very easily, which is important when you're presenting your data. Again, certainly not impossible using other tools.

Andrew Edgecombe
+2  A: 

Seems to be pure inertia. Where it is in use, everyone is too busy to learn IDL or numpy in sufficient detail to switch, and don't want to rewrite good working programs. Luckily that's not strictly true, but true enough in enough places that Matlab will be around a long time. Like Fortran (in active use where i work!)

DarenW
+1  A: 

Personally, I tend to think of Matlab as an interactive matrix calculator and plotting tool with a few scripting capabilities, rather than as a full-fledged programming language like Python or C. The reason for its success is that matrix stuff and plotting work out of the box, and you can do a few very specific things in it with virtually no actual programming knowledge. The language is, as you point out, extremely frustrating to use for more general-purpose tasks, such as even the simplest string processing. Its syntax is quirky, and it wasn't created with the abstractions necessary for projects of more than 100 lines or so in mind.

I think the reason why people try to use Matlab as a serious programming language is that most engineers (there are exceptions; my degree is in biomedical engineering and I like programming) are horrible programmers and hate to program. They're taught Matlab in college mostly for the matrix math, and they learn some rudimentary programming as part of learning Matlab, and just assume that Matlab is good enough. I can't think of anyone I know who knows any language besides Matlab, but still uses Matlab for anything other than a few pure number crunching applications.

+2  A: 

I think you answered your own question when you noted that Matlab is "cool to work with matrixes and plotting things". Any application that requires a lot of matrix maths and visualisation will probably be easiest to do in Matlab.

That said, Matlab's syntax feels awkward and shows the language's age. In contrast, Python is a much nicer general purpose programming language and, with the right libraries can do much of what Matlab does. However, Matlab is always going to have a more concise syntax than Python for vector and matrix manipulation.

If much of your programming involves these sorts of manipulations, such as in signal processing and some statistical techniques, then Matlab will be a better choice.

Mark Reid
Hmmm, I gotta disagree with you a little bit... with NumPy, Python's vector/array manipulation syntax is basically as simple as MATLAB's. And for >2-dimensional matrices, MATLAB gets very messy while NumPy is perfectly consistent.
Dan
You maybe right but I guess it aesthetics. Even after looking through all of [this table](http://www.scipy.org/NumPy_for_Matlab_Users#head-5a9301ba4c6f5a12d5eb06e478b9fb8bbdc25084) of Matlab to NumPy equivalents I still think Matlab is slightly neater. Haven't used either for tensors though.
Mark Reid
The libraries provided with Matlab are much more than anything I've seen with numpy.
Nathan Fellman
+9  A: 

MATLAB is a popular and widely adapted piece of a sophisticated software package. It'd be a mistake to think it's merely a math software since it has a wide range of "toolboxes". I recently used Matplotlib to plot some data from a database and it did the job without needing all the bells and whistles of MATLAB. However, it may not be proper to compare Python and MATLAB in every situation. As with everything else the decision depends on what you need to do.

I used MATLAB in undergrad for control systems design and simulation and also for image processing in grad school. For these fields MATLAB makes the most sense because of the powerful control and image processing toolboxes. As everyone mentioned, array operations, which are used in every MATLAB script you'd need to write, are very easy with MATLAB.

Another nice thing about MATLAB is that it's very easy and fast to do prototyping and trying out ideas using the built in toolbox functions. For instance, it takes no effort to import an image and compute it's histogram or do some simple processing on it. One disadvantage of MATLAB could be it's speed because of its interpreted nature. However, if one really needs speed than he can choose to implement the tested logic in C/C++, etc.

For further comparison with Python, I can say that MATLAB provides a full package for you to do your work without the need of looking around for external libraries and implementing extra functions.

One last point about MATLAB which I see is not mentioned in the answers here is that it has a very powerful visual modeling/simulation environment called Simulink. It's easier to design and simulate larger systems with Simulink.

Finally, again, it all depends on the problem you need to solve. If your problem domain can make use of one of MATLAB's toolboxes and you have access to MATLAB then you can be sure that you'll have the right tool to solve it.

Turker
+3  A: 

MATLAB WAS a wrapper around commonly available libraries. And in many cases it still is. When you get to larger datasets, it has many additional optimizations, including examining and special casing common problems (reducing to sparse matrices where useful, for example), and handling edge cases. Often, you can submit a problem in a standard form to a general function, and it will determine the best underlying algorithm to use based on your data. For small N, all algorithms are fast, but MATLAB makes determining the optimal algorithm a non-issue.

This is written by someone who hates MATLAB, and has tried to replace it due to integration issues. From your question, you mention getting MATLAB 5 and using it for a course. At that level, you might want to look at Octave, an open source implementation with the same syntax. I'm guessing it is up to MATLAB 5 levels by now (I only play around with it). That should allow you to "pass your exam". For bare MATLAB functionality it seems to be close. It is lacking in the toolbox support (which, again, mostly serves to reformulate the function calls to forms familiar to engineers in the field and selects the right underlying algorithm to use).

ramanman
+8  A: 

Hold everything. When's the last time you programed your calculator to play tetris? Did you actually think you could write anything you want in those 128k of RAM? Likely not. MATLAB is not for programming unless you're dealing with huge matrices. It's the graphing calculator you whip out when you've got Megabytes to Gigabytes of data to crunch and/or plot. Learn just basic stuff, but also don't kill yourself trying to make Python be a graphing calculator.

You'll quickly get a feel for when you want to crunch, plot or explore in MATLAB and when you want to have all that Python offers. Lots of engineers turn to pre and post processing in Python or Perl. Occasionally even just calling out to MATLAB for the hard bits.

They are such completely different tools that you should learn their basic strengths first without trying to replace one with the other. Granted for saving money I'd skimp on ease and learn to work with sparse matrices in Perl or Python.

dlamblin
+16  A: 
Mr Fooz
The documentation of Matlab is really exceptional. Nothing I've seen compares to it.
Nathan Fellman
+2  A: 

MATLAB is a fantastic tool for

  • prototyping
  • engineering simulation and
  • fast visualization of data

You can really play with, visualize and test your ideas on a data set very effectively. It should not be regarded as an alternative to other software languages used for product development. I highly recommend it for the above tasks, though it is expensive - free alternatives like Octave and Python are catching up.

Fredriku73
+3  A: 

I know this question is old, and therefore may no longer be watched, but I felt it was necessary to comment. As an aerospace engineer at Georgia Tech, I can say, with no qualms, that MATLAB is awesome. You can have it quickly interface with your Excel spreadsheets to pull in data about how high and fast rockets are flying, how the wind affects those same rockets, and how different engines matter. Beyond rocketry, similar concepts come into play for cars, trucks, aircraft, spacecraft, and even athletics. You can pull in large amounts of data, manipulate all of it, and make sure your results are as they should be. In the event something is off, you can add a line break where an error occurs to debug your program without having to recompile every time you want to run your program. Is it slower than some other programs? Well, technically. I'm sure if you want to do the number crunching it's great for on an NVIDIA graphics processor, it would probably be faster, but it requires a lot more effort with harder debugging.

As a general programming language, MATLAB is weak. It's not meant to work against Python, Java, ActionScript, C/C++ or any other general purpose language. It's meant for the engineering and mathematics niche the name implies, and it does so fantastically.

+1  A: 

Matlab is good at doing number crunching. Also Matrix and matrix manipulation. It has many helpful built in libraries(depends on the what version) I think it is easier to use than python if you are going to be calculating equations.

Ben Fossen