Quote:
Originally Posted by Dmentor
... knowing C well can be helpful but to me the minor syntax differences with MATLAB are also very annoying.
|
This is very true. My originally typed posted started listing some of the differences, but I decided to omit that part.
I remember having those frustrations when I first really started using Matlab. I relived that when I first started using LabVIEW: it was close enough to Simulink that I would try things that I would do in Simulink but it didn't work that way in LabVIEW, and that caused some frustration. I guess when things are really close to each other you tend to skip the documentation and just try to do it how it would make sense given the pattern up to that point. That's where the nice online documentation comes in handy.
Anyway, certain things in Matlab are very C-like, such as low-level file reading and writing, which are almost identical to how you do it in C. In fact, you'll find a lot of things where the people at the Mathworks just kept it as C-like as possible.
Other things that are different but can be annoying if you really know C:
- All Matlab arrays use matrix notation. That means the first index is 1 (NOT 0!!!!!)
- Operations can be performed on arrays/matricies and they follow the rules of matrix algebra, so be careful. You can always force element-wise operation by preceding your operator with a period. For example: a = b .* c;
- operating on subsets of arrays/matricies can be tricky (Be prepared to pull your hair out with some "arrays aren't the same size" errors). Get to know the array range operator (Ex: Array(1:10) means to use elements 1 through 10 of the array.) One cool thing is Array(5:end) automatically goes to the end (no need to know how many elements there are).
- if/elseif/else uses a slightly unique syntax. Very close to C, but not quite.
- There are no {} for code blocks. All loops and if constructs end with the "end" statement
- for loop syntax is for i = startvalue:stepsize:endvalue which is a really nice syntax actually. Stepsize is optional.
There are also some really cool things, like you can have multiple output arguments for a function. No need to pass pointers if you need multiple outputs. Also, all of the built in matrix operations and graphical functions are lifesavers. They are what turn Matlab from a nice novel programming language into the wonderful tool that it is. Not to mention that the debugger is quite good.
Anyway, enjoy learning it. It really is my go-to PC programming language unless I need to do some insanely fast computations.