MATLAB for Python programmers

前端 未结 6 2033
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 15:58

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

相关标签:
6条回答
  • 2021-02-05 16:26

    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.

    0 讨论(0)
  • 2021-02-05 16:30
    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.

    0 讨论(0)
  • 2021-02-05 16:36

    You can't do indexing on function result directly;

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

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

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

    This is from Jonas's tutorial.

    0 讨论(0)
  • 2021-02-05 16:42

    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:

    • MATLAB Central Blogs

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

    0 讨论(0)
  • 2021-02-05 16:45

    A couple of performance issues:

    1. Don't use classes: MATLAB classes are really really slow.

    2. Don't use for loops: Learn how to vectorize operations. MATLAB is fast at vectorized functions and exorbitantly slow when doing for loops.

    0 讨论(0)
  • 2021-02-05 16:47

    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:

    • The "Comparison with MATLAB" section of this Numerical Computing in Python presentation
    • NumPy for MATLAB Users cheat sheet

    But none of these really explain the MATLAB language and data structures to me 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.)

    0 讨论(0)
提交回复
热议问题