Academic Block

Overview of MATLAB Get Certified

MATLAB, short for MATrix LABoratory, is a powerful programming platform designed for numerical computing, data analysis, algorithm development, and visualization. It is widely used in engineering, science, and mathematics fields due to its extensive toolbox and intuitive programming language.

MATLAB was developed in the late 1970s by Cleve Moler, a professor at the University of New Mexico. It was initially created as a tool to provide students with easy access to LINPACK and EISPACK, powerful numerical libraries for matrix computation. In 1984, MATLAB was commercialized by MathWorks, co-founded by Moler, Jack Little, and Steve Bangert. Over the years, MATLAB has evolved into a comprehensive platform for numerical computation and is now widely used in academia and industry.

Features of MATLAB

MATLAB provides the following key features:

  • Interactive Environment: An integrated development environment (IDE) with debugging, editing, and visualization tools.
  • Matrix-Centric Computing: All data is naturally handled as matrices, which simplifies operations on large datasets.
  • Built-in Functions: Thousands of pre-defined functions for linear algebra, signal processing, image processing, and more.
  • Visualization: High-quality plots and graphs that enable clear and concise data representation.
  • Toolboxes: Specialized tools for applications such as optimization, statistics, machine learning, and system modeling.

Getting Started with MATLAB

When you open MATLAB, you are greeted with the MATLAB Desktop. It consists of several components:

  1. Command Window: The area where you type commands and execute them interactively.
  2. Workspace: Displays all the variables currently in memory.
  3. Current Folder: Shows files and scripts in the working directory.
  4. Editor: Used to write and save scripts and functions.

Basic Syntax and Commands

Here are some essential MATLAB commands to get you started:

1. Displaying Output

What this code does: This example teaches three fundamental ways to show information in the Command Window. disp is the simplest method — it prints whatever you give it (text or a number) and automatically adds a new line. fprintf gives you precise control over formatting (here %d inserts an integer). Notice that after assigning x = 10, both disp(x) and fprintf can display its value.

% Displaying text and variables
disp("Welcome to MATLAB!");
x = 10;
disp(x);
fprintf("The value of x is: %d\n", x);

Expected output in the Command Window:

Welcome to MATLAB!
10
The value of x is: 10

2. Defining Variables

What this code does: MATLAB does not require you to declare the type of a variable. You simply write a name, an equals sign, and a value. Here we create two numbers (a and b), add them together, store the result in a new variable called total, and then display that result. This is the most common pattern you will use every day in MATLAB. (We avoid naming the variable sum, because sum is a built-in MATLAB function and a variable with that name would hide it.)

% Defining variables
a = 5;
b = 3;
total = a + b;
disp(total);

Expected output:

8

Basic Operations

3. Arithmetic Operations

What this code does: This example demonstrates the four basic arithmetic operators in MATLAB: + (addition), - (subtraction), * (multiplication) and / (division). Each result is stored in its own variable and then printed. Notice that MATLAB follows the normal order of operations and that the results are exact for these integer values.

% Arithmetic Operations
x = 10;
y = 5;
add = x + y; % Addition
sub = x - y; % Subtraction
mul = x * y; % Multiplication
div = x / y; % Division
disp(add);
disp(sub);
disp(mul);
disp(div);

Expected output:

15
5
50
2

4. Creating Arrays

What this code does: Arrays are the heart of MATLAB. A row array is created by writing numbers inside square brackets separated by spaces (or commas). A column array is created the same way but with semicolons between the numbers. The two disp commands show the visual difference: the first prints horizontally, the second prints vertically.

% Creating Arrays
row_array = [1 2 3 4 5]; % Row array (1×5)
col_array = [1; 2; 3; 4; 5]; % Column array (5×1)
disp(row_array);
disp(col_array);

Expected output:

 1 2 3 4 5
1
2
3
4
5

Useful MATLAB Functions

These built-in commands help you manage the workspace and Command Window while you work:

Command
Description
clc
Clears the Command Window (makes the screen clean).
clear
Removes all variables from the Workspace.
clear all
Removes all variables and also clears functions and MEX-files from memory (more thorough than clear).
close all
Closes every figure window that is currently open.
who
Lists the names of all variables currently in the Workspace.
whos
Shows a detailed table of every variable (name, size, type, memory).

Practice Questions

Test Yourself

1. Open MATLAB and create a row array with the values [10, 20, 30, 40].

2. Use the fprintf function to display the array in a nicely formatted sentence.

3. Compute the sum, mean, and product of the array using the built-in functions sum, mean and prod.