This post explains how to use subplot in MATLAB with examples. Subplot command is used to create multiple plots in a grid layout. Syntax To divide the figure into an m x n grid and create an axes / new plot at position p, we can write The first subplot (p = 1) is the…
Category: MATLAB
Writing Vectorized MATLAB Code
Introduction This tutorial demonstrates benefits of writing vectorized MATLAB code which runs orders of magnitude faster than non-vectorized code. A loop is usually used if you want to perform same calculations on selected elements of an array. Vectorization is much faster alternative which can do the same in a single statement (or at least much…
How to Index a 2D Matrix in MATLAB
Introduction In this tutorial we learn how to index a 2D Matrix or array in MATLAB. Properly indexing arrays is necessary to use MATLAB effectively. This tutorial will teach you various ways to properly access modify or use values stored in a 2D array. Before discussing indexing, it is important to review how data is…
How to Index a Vector in MATLAB
Introduction In this tutorial we learn how to index a vector in MATLAB. Properly indexing vectors is necessary when working with them in MATLAB. If you want to use MATLAB effectively then understanding this topic can help you a lot in learning to properly access modify or use values stored in a vector. Defining a…
How to create a MATLAB Function
Introduction to Functions The goal of this tutorial is to explain how to create a MATLAB function. Function is a set of statements that performs a specific task. MATLAB has thousands of builtin functions like sin(), log(), randn(). MATLAB also allows the programmer to create their own functions. Creating function allows reuse of a set…