โ† Back to Learning Home

Learn MATLAB โ€“ Part 1

Introduction, Variables, Functions, and Image Processing Basics

โฌ‡ Download MATLAB

1. What is MATLAB?

MATLAB is a high-level programming language and environment used for numerical computation, data analysis, visualization, and algorithm development. It is widely used in engineering, physics, and computer science.

๐Ÿ’ก MATLAB is particularly strong for **matrix operations**, **data visualization**, and **image processing**.

2. Variables and Basic Operations

Create variables easily; MATLAB automatically handles types.

x = 10;
y = 5;

z = x + y;
disp(z)   % displays 15

A = [1 2 3; 4 5 6]; % a 2x3 matrix
B = A * 2;           % multiply each element by 2
disp(B)

3. Plotting Data

Visualize data quickly using built-in plotting functions.

x = 0:0.1:2*pi;
y = sin(x);

plot(x, y)
xlabel('x')
ylabel('sin(x)')
title('Simple Sine Wave')
grid on
โœ… MATLAB makes plotting and analyzing data intuitive.

4. Image Processing Basics

MATLAB has powerful tools for reading, displaying, and manipulating images.

img = imread('peppers.png'); % read an image
imshow(img);                  % display image

grayImg = rgb2gray(img);      % convert to grayscale
imshow(grayImg)

bwImg = imbinarize(grayImg);   % convert to black & white
imshow(bwImg)
๐Ÿ’ก Functions like imread, imshow, and rgb2gray are part of MATLAB's **Image Processing Toolbox**.

5. Creating Your Own Functions

Functions allow you to reuse code efficiently.

function y = squareNum(x)
    y = x^2;
end

result = squareNum(5);
disp(result)  % prints 25
โœ… Save each function in a separate file with the same name as the function.

6. Using MATLAB Libraries / Toolboxes

MATLAB comes with many built-in libraries and toolboxes.

% Example: Using Image Processing Toolbox
img = imread('peppers.png');
edges = edge(rgb2gray(img), 'Canny');  % detect edges
imshow(edges)
๐Ÿ’ก Toolboxes extend MATLAB with specialized functions for image processing, signal processing, machine learning, and more.

7. What to Learn Next