How to use MATLAB
Hello everyone! I hope you all will be absolutely fine and having fun. Today, I am going to share my knowledge about
How to use MATLAB. This is an on demand tutorial. The tutorial will help you to learn the the basics of the MATLAB and will elaborate the use of the different tools of it e.g. command window, m.file, Graphical User Interface (GUI) and simulink. Before into the details of this tutorial you must go through
Introduction to MATLAB first for the better understanding of this tutorial. Each of the tools has its own importance while making an algorithm in MATLAB. Command window basically deals with the shorter commands where there is a need of quick execution. Command window shows the result of all of the executed commands if there is no semicolon at the end of the particular statement. You must also have a look at
Declaration of Variables in MATLAB.
MATLAB provides high level of technical computing. It provides an easy to use environment for computation and programming to solve problems and their solutions can be expressed in mathematical symbolic notations. MATLAB can be used for a lot purposes e.g. computational mathematics, simulation, mathematical modeling, engineering graphics, data analysis, prototyping etc. MATLAB works on the basis of matrices whose basic building is an array. MATLAB system has different parts which will be discussed later in this tutorial. MATLAB has a lot of tool boxes in order to provide easiness to the users. Signal processing tool, fuzzy logic tool, control systems tool and simulation tool are its major tools that are used most frequently.
How to use MATLAB
Here in the tutorial,
How to use MATLAB, I will tell you about the basics of the MATLAB and the necessary steps to use the different tools of the MATLAB e.g. command window, GUI, simulink and m.file. First of all I would like to tell you a brief description of the MATLAB software.
Parts of MATLAB
- There are five different main parts of the MATLAB.
- MATLAB Language.
- MATLAB Working Environment.
- Handle Graphics.
- MATLAB Mathematical Functional Library.
- MATLAB Application Program Interface.
- All of these five parts are shown in the figure below.
- The brief description of each of the part is given below.
1) MATLAB Language
It provides high level matrices language. This language includes the features like flow statements, data structures, object oriented programming, input/output etc. It provides the facilities for programming at lower as well as on higher scales. We have posted many Matlab projects in which I have used MATLAB Language, here are few of these projects:
2) MATLAB Working Environment
This part provides set of tools and facilities to the MATLAB users. The facilities include the management of variables in workspace, debugging, m.files and import and export of the desired data. MTALB working environment is shown in the figure below:
3) Handle Graphics
This is a MATLAB system for graphics and it includes image processing and data visualization in two dimensions as well as in three dimensions. It also includes the designing of complete Graphical User Interface in MATLAB. Handle graphics in MATLAB is shown in the figure below:
4) MATLAB Mathematical Functional Library
It has a wide range of computational algorithms from the lower level (e.g. sum, sine, cosine) to the higher level (e.g. matrices inverse, matrices eigen values etc.). Mathematical functional library is shown in the figure below.
5) MATLAB Application Program Interface (API)
It provides you a library to write C programs as well as Fortran programs which interact with the MATLAB. It provides a lot of facilities e.g. MAT files. MATLAB application program interface (API) is shown in the figure below.
- So that was the brief description of the five different parts of the MATLAB.
How to use MATLAB Command Window
Here in this section of the tutorial How to use MATLAB, I will tell you about the the steps to use the command window in MATLAB and its importance in different circumstances. Command window is used to display the results of the algorithm immediately. When you do not specify an output variable whose values is desired to be obtained, then MATLAB uses a variable named as
ans which is the short form of the word
answer. This step is shown in the figure below.
Command window is the window which displays the output in non-graphic form. The symbol
>> shows that the MATLAB is ready for the input to be entered.
- Here I would like to show you the use of command window.
- I have declared three different variables named as a,b and c.
- I have stored the value of the sum of first two variables in the third variable.
- The result is shown in the figure below.
- Command window will only display the result of that statement which has no terminating semi colon.
- Now I am going to compute the values of trigonometric functions.
- The result is shown in the figure below.
- So that was the overview of how to use MATLAB command window.
How to use MATLAB m File
Here in this section of the tutorial How to use MATLAB, I will tell you about how to use the m.file in MATLAB. It is also known as the editor in MATLAB. You must also visit
How to Create m.file in MATLAB for the better understanding.
- I am going to add the simple two of the variables and storing it into the third variable while creating m.file in MATLAB.
- The result of the above description is shown in the figure below.
- Now, I am going to plot a simple sinusoidal signal while creating an m.file in MATLAB.
- The source code is shown in the figure below.
- The resulted plotted sinusoidal signal is shown in the figure below.
- So, that was the brief description about How to create or use m.file in MATLAB.
Note:These are few MATLAB projects in which I have written the MATLAB code in m File:
How to use MATLAB Simulink
Here in this section of the tutorial How to use MATLAB, I will explain you that how to use this amazing tool of the MATLAB. It represents the source code in terms of different blocks. First of all I would like to tell you that how to open the simulink library in MATLAB.
- You need to follow the steps given below.
- Open your MATLAB software, a new window with different MATLAB sections will be appeared on your screen.
- Click on the encircled button as shown in the figure below.
- As you press this button, a new window having simulink library in it, will be opened on your screen.
- The simulink library is shown in the figure below.
- Now, I am going to generate two simple sinusoidal signal in MATLAB simulink.
- Press Ctrl+N and a new window will appear upon which we need to place the desired blocks.
- Go to the Sources and select the sine wave block from it.
- Drag this blcok and drop it on the second window as shown in the figure below.
- Similarly copy and paste the same block.
- Here I am going to add the both of the sinusoidal signals having phase shift of 90 with each other.
- I have placed a scope to observe the addition of the both of the signals visually.
- All of the above steps are shown in the figures below.
- The selection of the add block is shown in the figure below.
- The selection of the scope is shown in the figure below in order to visualize the results.
- Now, the complete source code for the addition of two sinusoidal signals is shown in the figure below.
- After making this algorithm just run the program by clicking on the button encircled in the above figure.
- Double click on the Scope in order to visualize the desired result.
- The result of the addition of both the signals is displayed on the scope and is shown in the figure below.
- So, that was the brief description about how to open and use simulink library in MATLAB.
How to use MATLAB GUI
In this section of the tutorial How to use MATLAB, I will explain you about how to create Graphical User Interface (GUI) in MATLAB and how to operate it. GUI displays the desired results visually which helps us in better understanding of the algorithm instead of observing the results in analog form or in digital data. It also provide better external look to the designed algorithm. You should also have a look at
How to Create a GUI in MATLAB. I have designed many projects using GUI in MATLAB so you go through these below projects:
In order learn that how to perform different tasks using GUI in MATLAB, you need to follow the below steps:
- Go to the command window and type guide there.
- The step is shown in the figure below.
- When you press Enter a new window will be appeared on your screen.
- Go to the Create New GUI and select the blank GUI and hence a new GUI will be opened and its source code will be generated automatically in m.file of the MATLAB.
- The above steps are shown in the figure below.
- Now, pres OK button and a GUI will be appeared on your screen.
- The GUI appeared on the screen is shown in the figure below.
- Now you can pick and place the buttons, tables and graphs from the left side of the GUI.
- I picked a graph, a table and a button from the left bar of the GUI.
- All of the above steps are shown in the figure below.
- That was the overview of the basics of the MATLAB.
So that is all from the tutorial How to use MATLAB. I hope you enjoyed this tutorial. If you face any sort of problem regarding anything, you can anytime ask me in comments, freely, without even feeling any kind of hesitation. I will try my level best to solve you issues in some better way, if possible. I will explore MATLAB and other software and hardware too in my later tutorials later and will surely share them with all of you guys as well. So, till then, Take Care :)