Learn MATLAB by Examples
R2023bMATLAB is a programming platform designed specifically for engineers and scientists to analyze and design systems and products that transform our world. The heart of MATLAB is the MATLAB language, a matrix-based language allowing for the most natural expression of computational mathematics.
These examples cover the core concepts of MATLAB, from its fundamental matrix and vector operations to data visualization, control flow, and data structures like structs and cell arrays.
Variables
Variables in MATLAB are created by assignment. This sample demonstrates how to define variables and suppress output.
Matrices
MATLAB stands for Matrix Laboratory. This example shows how to create, index, and perform operations on matrices.
Vectors
Vectors are essentially 1D matrices. This sample demonstrates row and column vectors, and the colon operator.
Functions
Functions allow you to modularize code. This example shows how to define functions with inputs and outputs.
Plots
Data visualization is a core strength of MATLAB. This sample demonstrates 2D plotting with labels and legends.
Loops
Loops allow you to repeat code. This example shows `for` loops iterating over vectors and `while` loops.
Conditionals
Conditional logic uses `if`, `elseif`, and `else`. This sample demonstrates decision making based on values.
Scripts
Scripts are files containing MATLAB code. This example shows how to structure a script with sections and comments.
Structures
Structures (structs) allow you to group related data using named fields. This sample shows creation and access.
Cell Arrays
Cell arrays are containers that can hold data of different types and sizes. This example demonstrates curly brace indexing.

