How to use MATLABHere 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 LanguageIt 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:
- DC Motor Speed Control in MATLAB.
- DC Motor Direction Control in MATLAB.
- Stepper motor Speed Control in MATLAB.
- Stepper Motor Direction Control in MATLAB.
2) MATLAB Working EnvironmentThis 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 GraphicsThis 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 LibraryIt 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 WindowHere 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 FileHere 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 SimulinkHere 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 GUIIn 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:
- ECG Simulation in MATLAB
- Speech Recognition in MATLAB using Correlation
- Eye Ball Detection in MATLAB
- Stepper Motor Direction Control using MATLAB
- 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.