MATLAB (matrix laboratory) is a numerical computing environment and fourth-generation programming language. Developed by MathWorks, MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages, including C, C++, and Fortran.
Although MATLAB is intended primarily for numerical computing, an optional toolbox uses the MuPAD symbolic engine, allowing access tosymbolic computing capabilities. An additional package, Simulink, adds graphical multi-domain simulation and Model-Based Design fordynamic and embedded systems.
MATLAB users come from various backgrounds ofengineering, science, and economics.
MATLAB, the application, is built around the MATLAB language. The simplest way to execute MATLAB code is to type it in at the prompt, >> , in the Command Window, one of the elements of the MATLAB Desktop. In this way, MATLAB can be used as an interactive mathematical shell. Sequences of commands can be saved in a text file typically using the MATLAB Editor, as a script or encapsulated into a function, extending the commands available.
Variables
Variables are defined with the assignment operator, =. MATLAB is a weakly dynamically typed programming language. It is a weakly typed language because types are implicitly converted.
It is a dynamically typed language because variables can be assigned without declaring their type, except if they are to be treated as symbolic objects, and that their type can change.
Values can come from constants, from computation involving values of other variables, or from the output of a function. For example:

MATLAB has several functions for rounding fractional values to integers:
 |
round(X): round to nearest integer, trailing 5 rounds to the nearest integer away from zero. For example, round(2.5) returns 3; round(-2.5) returns -3. |
 |
fix(X): round to nearest integer toward zero (truncate). For example, fix(2.7) returns 2; fix(-2.7) returns -2 |
 |
floor(X): round to the nearest integer toward minus infinity (round to the nearest integer less than or equal to X). For example, floor(2.7) returns 2; floor(-2.3) returns -3. |
 |
ceil(X): round to the nearest integer toward positive infinity (round to the nearest integer greater than or equal to X); for example, ceil(2.3) returns 3; ceil(-2.7) returns -2 |
Vectors/matrices
 |
MATLAB is a "Matrix Laboratory", and as such it provides many convenient ways for creating vectors, matrices, and multi-dimensional arrays. In the MATLAB vernacular, a vector refers to a one dimensional (1 ×N or N ×1) matrix, commonly referred to as an array in other programming languages. A matrix generally refers to a 2-dimensional array, i.e. an m×n array where m and n are greater than or equal to 1. Arrays with more than two dimensions are referred to as multidimensional arrays. |
 |
Indexing is one-based, which is the usual convention for matrices in mathematics, although not for some programming languages. |
 |
Matrices can be defined by separating the elements of a row with blank space or comma and using a semicolon to terminate each row. The list of elements should be surrounded by square brackets: []. Parentheses: () are used to access elements and subarrays (they are also used to denote a function argument list).
 |
 |
Sets of indices can be specified by expressions such as "2:4", which evaluates to [2, 3, 4]. For example, a submatrix taken from rows 2 through 4 and columns 3 through 4 can be written as:
 |
 |
A square identity matrix of size n can be generated using the function eye, and matrices of any size with zeros or ones can be generated with the functions zeros and ones, respectively.
 |
 |
Most MATLAB functions can accept matrices and will apply themselves to each element. For example, mod(2*J,n) will multiply every element in "J" by 2, and then reduce 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. This code, excerpted from the functionmagic.m, creates a magic square M for odd values of n (MATLAB function meshgrid is used here to generate square matrices I and J containing 1:n).
 |
Semicolons
Unlike many other languages, where the semicolon is used to terminate commands, in MATLAB the semicolon serves to suppress the output of the line that it concludes (it serves a similar purpose
Graphics


Structures
MATLAB supports structure data types. Since all variables in MATLAB are arrays, a more adequate name is "structure array", where each element of the array has the same field names. In addition, MATLAB supports dynamic field names (field look-ups by name, field manipulations etc)
Function handles
MATLAB supports elements of lambda-calculus by introducing function handles, a references to functions, which are implemented either in .m files or anonymous/nested functions
Secondary programming
MATLAB also carries secondary programming which incorporates the MATLAB standard code into a more user friendly way to represent a function or system.
Simulink
Simulink is a secondary program incorporated with MATLAB. It is a way to create or collaborate Equation(s) of Motion using an infrastructure of click, drag, and connecting blocks. These blocks are used to do many things including: defining variables, inputs, EOMs, Scopes, etc.
Classes
MATLAB supports classes, however the syntax and calling conventions are significantly different than in other languagues, because MATLAB does not have reference data types. For example, a call to a method

cannot normally alter any variables of object variable. To create an impression that the method alters the state of variable, MATLAB toolboxes use evalin() command, which has its own restrictions.
Object-oriented programming
MATLAB`s support for object-oriented programming includes classes, inheritance, virtual dispatch, packages, pass-by-value semantics, and pass-by-reference semantics.
Interfacing with other languages
MATLAB can call functions and subroutines written in the C programming language or Fortran. A wrapper function is created allowing MATLAB data types to be passed and returned. The dynamically loadable object files created by compiling such functions are termed "MEX-files"
Libraries written in Java, ActiveX or .NET can be directly called from MATLAB and many MATLAB libraries (for example XML or SQL support) are implemented as wrappers around Java or ActiveX libraries. Calling MATLAB from Java is more complicated, but can be done with MATLAB extension,which is sold separately by MathWorks, or using an undocumented mechanism called JMI (Java-to-Matlab Interface), which should not be confused with the unrelated Java Metadata Interface that is also called JMI.
As alternatives to the MuPAD based Symbolic Math Toolbox available from MathWorks, MATLAB can be connected to Maple or Mathematica.
License
MATLAB is a proprietary product of MathWorks, so users are subject to vendor lock-in. Although MATLAB Builder can deploy MATLAB functions as library files which can be used with .NET orJava application building environment, future development will still be tied to the MATLAB language.
|