MATLAB XYZ for Electrical Engineers | Get Started with MATLAB

MATLAB [Matrix Labortory] is a numerical computing software which is used by Electrical Engineers.

You can plot the three-dimensional graphs or can simulate your electrical models for testing their behavior.

Also, learn about Simulink for Electrical Engineers

Today you’ll learn the basic concepts, some lines of code and some terminologies that are essential to Get started with MATLAB.

Introduction to Main Screen

The main screen of MATLAB has different directories:


Command window is the main screen where you write the code.

Workplace stores the variable and their values.

Basic arithmetic calculations

MATLAB can be used as a calculator for performing the basic arithmetic operations. Simply write the equation and press Enter to obtain an answer.

Arithmetic addition


>> 5 + 6
ans =

how to add two numbers in matlab

Arithmetic subtraction


>> 26 – 6
ans =

Similarly, you can divide and multiply two numbers.


Variables can be used to store numbers as well to solve the expressions.

The following lines of code illustrate the use of variables in command window:

>> a = 5
a =5

>> b = 6b =6

>> c = a * b

c =


The figure below displays execution of above codes in

how to use variables in matlab

The Use of Semicolon (;)

Once you hit Enter button, MATLAB simply executes it. However one can suppress the output by using a semicolon (;) at the end of the line.

semicolon in matlab

Trigonometric functions

Trigonometric functions such as sin, cos, tan, cot, sec, cosec can be solved in MATLAB.

Code Output
sin(90) 0.8940
cos(90) -0.4481
tan(90) -1.9952
sec(90) -2.2318
csc(90) 1.1186
cot(90) -0.5012

The above codes are for radians. In case of degree the codes are:

Code Output
sind(90) 1
cosd(90) 0
tand(90) Inf
secd(90) -Inf
cscd(90) 1
cotd(90) 0

The M file in MATLAB

So far we entered our codes in MATLAB command window, there is another alternative way to enter the code. The MATLAB m-file is a simple text file where a user enters the command.

You can create an M-file in one hit.

Head to the top left the menu, click on File > New > M-file

how to create m file in matlab

You can run the same codes (which we executed previously) using the M-file.

M-file can also be used to take input from the user.

The following lines of code can be used to take input in MATLAB:

a = input(b);

Where a and b are two variables.

Let’s understand the use of input function to find the square of any number.

num = ‘Enter the number? ‘;
x = input(num);
y = x*x
str = input(num,’s’);

Leave a Reply