MATLAB® is a numerical computing environment and programming language. Created by The MathWorks, MATLAB allows easy matrix manipulation, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs in other languages. Although it specializes in numerical computing, an optional toolbox interfaces with the Maple symbolic engine, making it a full computer algebra system. It is used by more than one million people in industry and academia. The costs are $2000 for a commercial license without any toolboxes, and US$100 for an academic license with a limited set of Toolboxes.
x = 17defines a variable named x, and assigns it a value of 17. Values can come from literal values such as string constants or numeric immediates, or from the values of other variables, or from the output of a function.
MATLAB provides a simple way to define simple arrays using the syntax: init:increment:terminator. For instance:
array = 1:2:9
array =
1 3 5 7 9
defines a variable named array (or assigns a new value to an existing variable with the name array) which is an array consisting of the values 1, 3, 5, 7, and 9. That is, the array starts at 1, the init value, and each value increments from the previous value by 2 (the increment value), and stops once it reaches but not exceeding 9 (9 being the value of the terminator).
array = 1:3:9
array = 1 4 7 the increment value can actually be left out of this syntax (along with one of the colons), to use a default value of 1. ari = 1:5
ari =
1 2 3 4 5
assigns to the variable named ari an array with the values 1, 2, 3, 4, and 5, since the default value of 1 is used as the incrementer.
* = meshgrid(1:n); A = mod(I+J-(n+3)/2,n); B = mod(I+2*J-2,n); M = n*A + B + 1;
Note that this code performs operations on vectors and matrices without the use of "for" loops. Idiomatic MATLAB programs usually operate on whole arrays at a time. The MESHGRID utility function above creates arrays like these:
J =1 2 3 1 2 3 1 2 3
I =
1 1 1 2 2 2 3 3 3
Most scalar functions can also be used on arrays, and will apply themselves in parallel to each element. Thus mod(2*J,n) will (scalar) multiply the entire J array with 2, before reducing each element modulo n.
MATLAB does include standard "for" and "while" loops, but using MATLAB's vectorized notation often produces code that is easier to read and faster to execute.
The language shows a mixed heritage with a sometimes erratic syntax. For example, MATLAB uses parentheses, e.g. y = f(x), for both indexing into an array and calling a function. Although this ambiguous syntax can facilitate a switch between a procedure and a lookup table, both of which correspond to mathematical functions, a very careful reading of the code is required to establish the original intent.
Though other datatypes are available, the default is a matrix of doubles. This array of numbers is devoid of important attributes required by real world data such as engineering units or sampling rates. Although time and date markers were added in SP3 with the time series object, the lack of sample rate information is a serious shortcoming for signal processing applications, where data is typically sampled at a constant interval. These attributes must be managed by the user with custom programming, which is error-prone and time-consuming.
Array indexing is one-based, which is inconvenient for expressing some mathematical ideas, especially those related to signal processing.
MATLAB is an imperative programming language, so it does not automatically update variables in response to input changes as one might want for simulations or exploratory data analysis. Consider, for example, the following fragment:
t = 1:100; y = log(t);
If variable t changes, e.g. t = 100:1000, the user must manually re-evaluate y to obtain the updated result. The MathWorks offers a supplementary package, Simulink, that partially automates these tasks for systems modeling and simulation applications.
MATLAB doesn't support references, which makes it very difficult to implement data structures which contain indirections, such as open hash tables, linked lists, trees, and various other common computer science data structures. In addition, it makes the use of objects cumbersome, because every change in the object creates a new object instead of changing the current one ("this" or "self" is Copy-On-Write). The only way to change an object property is to "overwrite" the old object by the new object that was created after the property change, like this:
obj = do_something(obj);
instead of the more common idioms in other languages:
obj.do_something();
Despite these shortcomings, MATLAB continues to be employed in many technical computing applications, though several viable competitors are emerging.
Array programming languages | Computer algebra systems | Domain-specific programming languages | IRIX software | Numerical programming languages
MATLAB | MATLAB | MATLAB | MATLAB | متلب | Matlab | MATLAB | MATLAB | MATLAB | MATLAB | MATLAB | Matlab | MATLAB | MATLAB | MATLAB | MATLAB | แมตแล็บ | Matlab | MATLAB