# Matrices and arrays in MATLAB

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:

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

**Transpose matrix:**Transposing a matrix means interchanging the rows and columns. Use single quote (‘) to transpose a matrix and perform matrix multiplication as follows as shown below.

**Multiplication:**To perform element wise multiplication instead of matrix multiplication, use ‘.*’ as shown below.

**Inverse of matrix:**To find inverse of a matrix, use function ‘inv()’ (image below)

**Concatenate arrays**: Two arrays are joined using square brackets as shown below.This is called horizontal concatenation wherein the number of rows in the concatenation arrays should be equal. Similarly, use a semicolon for vertical concatenation . In vertical concatenation, number of columns in two concatenating arrays should be equal as shown below.

**Complex and imaginary numbers**: Complex numbers have area part and an imaginary part that is square root of -1 as stated in the image below. Furthermore, MATLAB uses i or j to represent an imaginary part in a number as shown in image 9 b).

#### Reference

- Barnett, G., & Tongoa, L. Del. (2008).
*Data Structures and Algorithms*(1 st). Retrieved from http://lib.mdp.ac.id/ebook/Karya Umum/Dsa.pdf

- Matrices and arrays in MATLAB - November 15, 2018
- What is a systematic review of the literature? - October 29, 2018
- Structural equation model (SEM) - March 20, 2018

## Discuss