# Matrices and arrays in MATLAB

By Soumya Srivastava & Shruti Datt on November 15, 2018

The basics of MATLAB were discussed in the previous module. It covered topics on interface of MATLAB software and the basic operations of MATLAB along the help and documentation features. Furthermore, this article discusses the matrices and array part of MATLAB.

Array is an arrangement of elements in a way that all the elements in this arrangements are similar in terms of size, data type and are arranged one after other continously in the memory (Barnett & Tongoa, 2008). Matrix (matrices in plural form) is a multidimensional array. In the present module the different operations on array, their use and methods to use array, traversing in array and  functions available for array in MATLAB are focused .The present article discusses about the basics of array and the basic operations that can be performed on an array.

## Array creation

Enter elements in a row and separate the elements either by a comma or a space in order to create arrays as shown below.

The image above presents a row vector. In order to create a column matrix, separate each number by semicolon as shown below. Furthermore, separate rows by semicolon to create matrix with multiple rows as shown in image 3.

Use functions like zeros, ones or rand to create a matrix. Use function ‘zero( )’ to create a matrix with all zeros, ‘ones( )’  creates matrix with all elements with one and finally ‘rand( )’  is used to create a matrix with random numbers. Pass the size of the matrix as arguments in these functions as shown in image below.

## Operations applied on Matrices

Different operations can be applied on matrices, using a single arithmetic operator like transpose of matrices, inverse of matrices or matrices multiplication both row wise and column wise, element wise multiplication and many more.  Single arithmetic operations are as follows:

1. Trigonometric functions: To perform trigonometric operations, pass the elements or the variables  as arguments in the trigonometric functions as shown below.