Programming |
Creating and Concatenating Matrices
MATLAB is a matrix-based computing environment. All of the data that you enter into MATLAB is stored in the form of a matrix or a multidimensional array. Even a single numeric value like 100
is stored as a matrix (in this case, a matrix having dimensions 1-by-1):
Regardless of the data type being used, whether it is numeric, character, or logical true
or false
data, MATLAB stores this data in matrix (or array) form. For example, the string 'Hello World'
is a 1-by-11 matrix of individual character elements in MATLAB. You can also build matrices composed of more complex data types, such as MATLAB structures and cell arrays.
To create a matrix of basic data elements such as numbers or characters, see
To build a matrix composed of other matrices, see
Constructing a Simple Matrix
The simplest way to create a matrix in MATLAB is to use the matrix constructor operator, []
. Create a row in the matrix by entering elements (shown as E
below) within the brackets. Separate each element with a comma or space:
For example, to create a one row matrix of five elements, type
To start a new row, terminate the current row with a semicolon:
This example constructs a 3 row, 5 column (or 3-by-5) matrix of numbers. Note that all rows must have the same number of elements:
The square brackets operator constructs two-dimensional matrices only, (including 0-by-0, 1-by-1, and 1-by-n matrices). To construct arrays of more than two dimensions, see Creating Multidimensional Arrays.
For instructions on how to read or overwrite any matrix element, see Matrix Indexing.
Data Structures | Specialized Matrix Functions |
© 1994-2005 The MathWorks, Inc.