March 14

MATLAB Array: Create and Define Types

MATLAB Array: Create and Define Types

Tandose Sambo

Table of Contents (click to navigate)

  1. Introduction to Arrays
  2. Matlab Arrays: Brief Tutorial
  3. Conclusion
  4. References

Introduction to Arrays

Mathematical arrays are all around us. If you take the time to process nature, even your own self, you’ll realize that there is an ordered array of objects in the Universe. The solar system itself has the planets orbiting around the sun in an ordered pattern. Cells are organized in a geometric array, and additionally, in images like the above organisms can create physical structures that have a geometric order to them. Order is the nature of the Universe. In a similar manner, the aim of science and mathematics is to model this order using numbers.

Mathematical arrays, similar to the image above, is a reference to a set of numbers or objects in a specific pattern. This is an organized pattern of numbers in a matrix containing rows and columns. Mathematical manipulations of arrays can then be conducted, once the the data is arranged in a suitable array.

Matrices are used for a variety of applications in both science and engineering. The purpose of this tutorial is to identify the different ways that matrices can be represented in the MATLAB R2018b environment.

MATLAB, as a matrix based system is composed of a series of multi-dimensional arrays of data. Due to the various syntaxes that the system possesses, we will attempt to discuss the surface discussions, and then delve into the details of any interesting topics in later tutorials.

The rules for matrix arithmetic are straight forward, and MATLAB is equipped to handle the manipulations of hundreds of thousands of variables. While different from general mathematics, matrix arithmetic has its merits when it comes to detailed science and engineering calculations. With matrix arithmetic – addition, multiplication, multiplication by a scalar, finding the inverse, are a few simple manipulations that the system can facilitate.

Image Credit:

MATLAB Array Brief Tutorial

For the purposes of this tutorial, let us go through the process of describing some Matrix functions, and manipulating them in the MATLAB user environment.

Starting with a fresh command page, we will start the process of entering some arrays into the MATLAB system. The simplest matrix that exists in the system is the zero matrix. This matrix is comprised of all zeroes in the rows and all zeroes in the columns. The MATLAB syntax enables you to determine the number of rows that you want to have in your matrix.

Let’s start with the following code:


Entering the code into MATLAB, the system will process, and generate the following output:

Additionally, if you so desire to create matrices of varying columns of the number one, you can use the following code:


As you can see from the above syntax, the column identity is in the first numeral of the syntax (5 in this instance), while the rows are denoted by the second numeral after the comma. This is the numeral 8 in this instance. Generating the one matrix can allow the user to facilitate further downstream manipulations.

If you want to get really creative with your matrices, you can use the rand() function in MATLAB. This function is one that allows the system, in a lottery like fashion, to create matrix arrays. Depending on the types of simulations that you may be running, this function will come in handing for testing and validating your data, after you have generated a mathematical model. Let us see what happens when the following code is entered in the system.

rand(6, 9)

In a previous matrix transformation tutorial we had encountered the magic square. While for the most part, you’ll use this when you’re in the process of learning your MATLAB syntax, for grins, let’s go ahead and go through the process of finding out what happens when we use the magic function on a matrix that contains five rows. Now’s the time to use our imaginations, so let’s go ahead and let MATLAB work it’s magic. Waving our wands, and letting MATLAB calculate, the following is what we see:


Voila! What do we find when we enter the magic rubric into our command center? This is the matrix…where the same sum is generated on all aspects of the matrix. Whether you add all the components of a row, a column or a diagonal, you end up with the same sum. Again, this is one of those matrices that you play with initially, but eventually when you are validating a model, later down the line, and need input of a certain format, it will be helpful to you to know this function.

When it comes to arrays, there are a myriad of options available in the MATLAB pool, that facilitate the desired function. The following detailed table, outlines the functions that are available to the user when it comes to the world of arrays. Ordering numbers is just the first step, the second is the use of that data to generate information.

Function Purpose
length Length of vector or largest array dimension
ndims Number of array dimensions
numel Number of array elements
size Array dimensions
iscolumn Determines whether input is column vector
isempty Determines whether array is empty
ismatrix Determines whether input is matrix
isrow Determines whether input is row vector
isscalar Determines whether input is scalar
isvector Determines whether input is vector
blkdiag Constructs block diagonal matrix from input arguments
circshift Shifts array circularly
ctranspose Complex conjugate transpose
diag Diagonal matrices and diagonals of matrix
flipdim Flips array along specified dimension
fliplr Flips matrix from left to right
flipud Flips matrix up to down
ipermute Inverses permute dimensions of N-D array
permute Rearranges dimensions of N-D array
repmat Replicates and tile array
reshape Reshapes array
rot90 Rotates matrix 90 degrees
shiftdim Shifts dimensions
issorted Determines whether set elements are in sorted order
sort Sorts array elements in ascending or descending order
sortrows Sorts rows in ascending order
squeeze Removes singleton dimensions
transpose Transpose
vectorize Vectorizes expression


As you venture into the world of MATLAB, you’ll realize that there are a myriad of ways that you can utilize matrix arrays to organize and manipulate your data. Taking the time to understand the syntax will be key to ensuring that your scientific or engineering systems are operating at their best. The key to good process modeling, is ensuring that you’re adequately represent your system well. The matrix is that ideal data organization format, and it allows infinite possibilities where data transformation from a mathematical perspective is concerned. Allow yourself to become familiar with the system, in order to achieve the utmost in your operational needs.


Arrays In Mathematics:

MATLAB Arrays:

Loved this? Spread the word

About the Author

Tandose Sambo is a Chemical Process Engineer, with a focus on improving process efficiency via operational improvements. Six-Sigma certified, and with a Design-focus and Data Analytics interest, she is a driven growing entrepreneur, with the intention to optimize industrial and business process operations. Her interests include sharing time with family and travelling.

Tandose Sambo

Related posts

How to Use Bill of Materials (BOM) in SolidWorks: Review Beginner’s Guide

​Read More

Compare Autodesk Inventor vs Fusion 360: Review Which One to Buy

​Read More

How to Use Convert Entities Tool in SolidWorks: Beginner Tutorial

​Read More

[May 2020] Best Free CAD Design Software for Mac

​Read More
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Subscribe to our newsletter now!