DEV Community

Cover image for Introduction To MATLAB For Engineers
Dumebi Okolo
Dumebi Okolo

Posted on

7 2 2 3 2

Introduction To MATLAB For Engineers

If you're an engineering student or professional, chances are you've heard of MATLAB. Whether you're working on simulations, data analysis, system modeling, or algorithm development, MATLAB is a valuable tool. It’s especially powerful in handling engineering-specific problems that involve a lot of matrix math, plotting, and data manipulation.

Math is for everyone! Everyone loves maths!

a gif with

Pursuant to my degree in Information and Telecommunications Engineering, we are going through a series of programming languages and concepts. Our last module was on data analysis with Excel/Sheets and SPSS. This current module is on applied/advanced mathematics with MATLAB. Before starting this module, I was asked, "Why learn MATLAB when you can get whatever you need with Excel or Python?"

I hope this article provides that answer to that question and other questions.


Table of Contents

 1. What is MATLAB?
 2. Is MATLAB Free To Use?
 3. Is MATLAB a Programming Language?
 4. Difference Between MATLAB and Python
 5. Does Anyone Still Use MATLAB?
 6. Basic MATLAB Syntax
 7. Do While in MATLAB
 8. How to Plot in MATLAB
 9. MATLAB For Loop
 10. Use Cases for MATLAB


What is MATLAB?

MATLAB (short for MATrix LABoratory) is a high-level programming environment developed by MathWorks, primarily aimed at engineers and scientists. It's widely used for numerical computing, visualization, algorithm development, and building applications and simulations. What sets MATLAB apart is its built-in support for matrix operations, which are foundational to many engineering computations. It also offers a rich ecosystem of toolboxes for different fields such as signal processing, machine learning, robotics, and more.

Beyond its computational power, MATLAB provides an intuitive environment with a command window, editor, workspace, and extensive documentation to make coding and debugging easier. Whether you're analyzing data, creating simulations, or prototyping algorithms, MATLAB gives you the tools to work efficiently.


Is MATLAB Free To Use?

No, MATLAB is not free. MATLAB operates under a commercial licensing model. Licenses are paid and can be costly for businesses and professional use. However, there are still ways to access MATLAB for free depending on your status and needs:

  • MATLAB Online: MathWorks offers a web-based version with limited functionality that you can use without installing anything. It's ideal for beginners or those with lighter computational needs.
  • Student License: Offered at a heavily discounted rate for university students. This version usually includes most core toolboxes.
  • Free Trial: MathWorks provides a trial version that allows users to explore MATLAB's features for a limited time.

While the full version is paid, these options make it accessible for learning and experimentation.


Is MATLAB a Programming Language?

Yes, MATLAB is both a programming language and an environment. The language is purpose-built for numerical and matrix-based operations. Unlike general-purpose languages like C or Java, MATLAB was created to simplify mathematical computation and visualization. It supports procedural, object-oriented, and some aspects of functional programming.

Its syntax is readable and easy to learn for those with a mathematical background, making it a popular first language for engineers. It also comes with an extensive library of MATLAB functions, which are optimized for speed and accuracy in technical tasks.


Difference Between MATLAB and Python

Both MATLAB and Python are widely used in engineering and data science, but they cater to slightly different audiences and use cases. Here's how they compare:

Feature MATLAB Python
Cost Paid license Free and open-source
Learning Curve Easy for engineers, math-oriented Broader, more general-purpose
Syntax Built around matrix operations Flexible but not matrix-first
Libraries Rich in engineering toolboxes Broader but needs third-party
Visualization Integrated plotting tools Requires packages like matplotlib
Community Academic and industrial Massive and open-source
Flexibility Specialized Highly adaptable and extensible

MATLAB shines in tasks that involve complex math and modeling, especially when performance and accuracy are critical. Python, however, offers greater flexibility and community support, making it ideal for software development and data science.


Does Anyone Still Use MATLAB?

Absolutely. MATLAB remains a staple in engineering education and industry. Many universities use MATLAB as a core part of their engineering curriculum (a good example is mine! and likely yours too!). It is also heavily used in industries such as:

  • Aerospace and Defense: For simulation, modeling, and control system design.
  • Automotive: For ADAS development, engine modeling, and testing.
  • Electrical Engineering: Signal and image processing, circuit simulation.
  • Finance: Risk modeling and quantitative analysis.

Although open-source alternatives like Python are growing in popularity, MATLAB's stability, comprehensive documentation, and specialized toolboxes keep it relevant and widely used.


Basic MATLAB Syntax

To get started with MATLAB, understanding its basic syntax is essential. Here are a few examples:

  • MATLAB is case-sensitive.
  • Statements end with a semicolon (;) to suppress output.
  • Most functions work directly with vectors and matrices.
  • To write a comment in MATLAB, you begin the statement with the percentage '%' sign.
  • Variables are declared with the equal to '=' sign.
  • The operator for addition in MATLAB is the plus '+' sign.
  • The operator for subtraction in MATLAB is the plus '-' sign.
  • The operator for division in MATLAB is the plus '/' sign.
  • The operator for multiplication in MATLAB is the plus '*' sign.
  • To print to your terminal or environment, you use the disp or fprintf keyword.
% This is a comment
x = 5;            % Variable assignment
y = x + 3;        % Addition
z = sin(pi/2);    % Using built-in functions (sine and pi)
disp(z);          % Display output
Enter fullscreen mode Exit fullscreen mode

MATLAB’s syntax is particularly efficient for expressing mathematical computations with fewer lines of code.


Do While in MATLAB

MATLAB does not have a native do-while loop structure, but you can simulate it using a while loop combined with a break condition. Here's an example:

x = 0;
while true
    x = x + 1;
    disp(x);
    if x >= 5
        break;
    end
end
Enter fullscreen mode Exit fullscreen mode

This loop mimics a do-while loop by executing at least once and checking the condition inside the loop.


How to Plot in MATLAB

Plotting is where MATLAB really stands out. Here's a simple example of how to generate a 2D sine wave plot:

x = 0:0.1:10;         % Generate a vector from 0 to 10 with increments of 0.1
y = sin(x);           % Compute sine of each element in x
plot(x, y);           % Plot y vs x
title('Sine Wave');   % Add title
xlabel('x');          % Label x-axis
ylabel('sin(x)');     % Label y-axis
grid on;              % Turn on grid
Enter fullscreen mode Exit fullscreen mode

screenshot of an active plot on MATLAB.
The screenshot above is the code example we have being run on MATLAB (online). As you can see, MATLAB instantly gives you options of how to customize the appearance of your plot.

MATLAB also supports 3D plotting, histograms, bar charts, and more. The plotting tools are interactive, allowing zooming, rotating, and exporting with ease.


MATLAB For Loop

The for loop in MATLAB is similar to other languages but works particularly well with vectors and arrays:

for i = 1:5
    disp(['Value: ', num2str(i)]);
end
Enter fullscreen mode Exit fullscreen mode

for loop in matlab

You can loop through arrays, use nested loops, or combine them with conditional statements. It's great for performing repetitive tasks like data transformation or batch simulations.


Use Cases for MATLAB

MATLAB functions and toolboxes make it a go-to tool across many engineering domains. Here are some typical use cases:

  • Signal Processing: Filter design, FFT analysis, and spectral analysis
  • Control Systems: PID design, system modeling, and stability analysis
  • Machine Learning: Classification, regression, and clustering with built-in apps
  • Image Processing: Feature extraction, enhancement, segmentation
  • Robotics: Robot simulation, path planning, kinematics, and dynamics
  • Data Analysis: Importing, cleaning, and visualizing data sets
  • Simulation: System-level modeling with Simulink integration

With hundreds of built-in MATLAB functions, you can handle complex computations without reinventing the wheel.


I write technical articles for companies and individuals. If you enjoyed this, you can connect with me on LinkedIn for a chat.

Below are some blogs that I write on!

The Handy Developer's Guide.

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

👋 Kindness is contagious

DEV is better (more customized, reading settings like dark mode etc) when you're signed in!

Okay