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.
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:
>> b = 6b =6
>> c = a * b
The figure below displays execution of above codes in
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.
Trigonometric functions such as sin, cos, tan, cot, sec, cosec can be solved in MATLAB.
The above codes are for radians. In case of degree the codes are:
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
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.
x = input(num);
y = x*x
str = input(num,’s’);