Math, Made Simple & Visual.
MATLAB is a computer language and a workspace built for numbers. It helps engineers and scientists solve hard math problems, draw clear graphs, and test real-world ideas.
Command Window
>> speed = 60;
>> time = 2;
>> distance = speed * time
distance =
120
The Core Rule: Everything is a Box
The name MATLAB stands for Matrix Laboratory. In normal math, you often work with one number at a time. In MATLAB, you put groups of numbers into a box called a "matrix".
Because it treats many numbers as one single box, it can do millions of calculations at the exact same time. This makes it incredibly fast.
The Four Main Parts of the Screen
When you open MATLAB, you see a neat layout. It is split into panels so you can write code, see your files, and check your saved numbers all at once.
- script.m
- data.csv
- plot.png
Saved memory:
- speed60
- time2
% Calculate fuel cost
distance = 120;
mpg = 30;
gallons = distance / mpg;
>> gallons
4
How It Remembers Information
To tell the computer to remember a piece of information, you create a "variable". You give it a name and an equal sign. MATLAB automatically figures out what kind of data it is.
Numbers (Scalars)
Just a single number. Used for simple math.
Words (Strings)
Text placed inside quote marks.
Lists (Vectors)
A line of numbers in square brackets.
Drawing Graphs is Very Easy
MATLAB is famous for its pictures. If you have a list of numbers, you can turn them into a line graph with just one word: plot().
% Make a list of months
x =;
% Make a list of sales
y =;
% Draw the line graph!
plot(x, y);
Toolboxes: Extra Superpowers
Out of the box, MATLAB is great at math. But you can also add "Toolboxes". A toolbox is a bundle of special codes written by experts for specific jobs. You don't have to write the hard math yourself; you just use their tools.
Signal Processing
Used to clean up audio, fix radio waves, or study heartbeats.
Image Processing
Used to make photos clearer, or teach computers to see faces.
Control Systems
Used to keep drones flying steady or keep self-driving cars on the road.
Machine Learning
Used to train computers to recognize patterns and make smart guesses.
Simulink: Coding Without Typing
MATLAB has a twin brother named Simulink. Instead of typing words to make a program, you drag and drop blocks onto the screen.
You connect the blocks with arrows to show how information flows. Engineers use this to build simulations of airplanes, car engines, and robots before they build the real thing. It saves millions of dollars in testing.
Saving Your Work (Scripts)
If you just type in the Command Window, your work goes away when you close the program. To save your steps, you put them in a text file called a Script. You can run this script any time, over and over again.
% This script calculates area of a circle
radius = 5;
pi_value = 3.14159;
area = pi_value * (radius * radius);
disp("The area is:");
disp(area);
Who Uses This Program?
Space Agencies
People who launch rockets use MATLAB to calculate exactly how much fuel to burn and what angle to point the ship so it reaches orbit safely.
Car Makers
Car companies create a fake car inside Simulink. They test the brakes on the computer a million times before they ever build a real brake pad.
Doctors & Scientists
When an MRI machine takes a picture of a brain, it is just a giant box of numbers. MATLAB turns those numbers into a 3D picture a doctor can look at.
Making Choices (If/Else)
Computers need rules to make decisions. You can tell MATLAB to do one thing if a rule is true, and something else if it is false. This is called an "if statement."
temp = 105;
if temp > 100
disp("Too Hot!");
else
disp("Normal.");
end
Doing Things Over and Over (Loops)
If you need to count to 1,000, you don't type 1,000 lines of code. You use a "loop." A loop tells the computer to repeat a block of code a certain number of times automatically.
% Count from 1 to 5
for count = 1:5
disp(count);
end
Making Your Own Tools (Functions)
Sometimes you have a special math trick you use every day. You can save it as a "function." This wraps your code into a neat, reusable box. You put numbers in, the box does the math, and it pushes the answer out.
Multiply by 10
Bringing Outside Numbers In
In the real world, your numbers usually come from Excel files or hardware sensors. MATLAB can easily suck thousands of rows from a spreadsheet directly into a matrix.
% Load an Excel file into MATLAB
data = readmatrix("sales.xlsx");
Sending Your Work Out
Once you finish crunching the numbers, you need to share the results with your boss or team. You can push your finished matrices back out into a brand new file or save your graphs as pictures.
% Save the matrix back to a file
writematrix(answers, "results.csv");
Making Pictures Pop (3D Graphs)
Line graphs are nice, but sometimes you need to see hills and valleys. MATLAB can turn a grid of numbers into beautiful 3D mountains using simple commands like surf().
% Create a 3D surface plot
Z = [1 2 1; 2 4 2; 1 2 1];
surf(Z);
The Free Math Tools
You don't have to write custom code to find averages or square roots. MATLAB comes with thousands of built-in math tools ready to use instantly. Just type the word and put your numbers in parentheses.
Leaving Notes for Yourself
If you write a lot of code, you might forget what it does by tomorrow. You can type a % sign to leave a "comment."
The computer completely ignores anything written after the % sign. These are just sticky notes to help human beings read the code.
% Step 1: Get user age
a = 30;
% Step 2: Multiply by dog years
d = a * 7; % 7 is the multiplier
Fixing Mistakes (Debugging)
>> speed = 50;
>> time = 2;
>> dist = speeed * time;
Unrecognized function or variable 'speeed'.
Everyone makes typing mistakes. When you type something wrong, MATLAB will stop and show an error message in red text. Don't panic!
This red text is actually your friend. It tells you exactly what went wrong (like a spelling mistake) and where to look so you can easily fix the typo.
Asking for Help
MATLAB has a giant, free encyclopedia built right in. If you don't know how to use a tool, you don't even need to search the web. Just type doc followed by the tool's name in the Command Window.
This instantly opens an official help page with clear instructions and copy-paste examples.
The Big Summary
- MATLAB is a powerful calculator for engineers and scientists.
- Everything is stored in boxes called Matrices, making it very fast.
- You can easily turn boring numbers into beautiful graphs using simple words.
- You can use Toolboxes or Simulink to build huge projects without writing everything from scratch.