How to Create m File in 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 Create m File in MATLAB. It is also known as New Script or Editor in the MATLAB. It's an amazing MATLAB tool. We can write the complete source code on editor. If we want to visualize the result of the particular statement we should not put a semicolon after that statement in MATLAB. Before going into the details of this tutorial, you must first have a look at Introduction to MATLAB and if you don't know about MATLAB variables then you must read Declaration of Variables in MATLAB. By doing this and by pressing the Run (Green Color) button at the top of the editor we will be able to see the result on the command window. In other words, we have to write the entire source code in the editor and to run the program and the desired results will be displayed on the command window. It is easy to do so as compared to write and manipulate every single statement on command window.

How to Create m File in MATLAB ???

Here, in the tutorial How to Create m File in MATLAB, I will show you the step by step procedure to create an m file in MATLAB first and then to observe the desired results on command window.
  • First of all you need to open your MATLAB software.
  • Go to the top left corner of the front window of the MATLAB and click on New Script.
  • The above steps are shown in the figure below.
  • A new window will be appeared on your screen right after clicking on the New Script.
  • The second window appeared on the screen is shown in the figure below and it is also known as an Editor.
  • A very simple code written on the editor by declaring three different kinds of variables and their manipulation is shown in the figure below.
  • Now, if you want to observe the result on the command window you have to do two things.
  • The first thing is to remove the semicolon at the end of the statement as shown in the figure above.
  • And the second thing is to press Run button encircled in the figure shown above.
  • After following all of the above steps you will be able to visualize the results on the command window of the amazing software i.e. MATLAB.
  • The result observed on the command window is shown in the figure below.
  • You can see the result is obtained in the form of an equation.
  • That was the detailed discussion on Creating m.file in MATLAB.
So, that is all from the tutorial Creating m.file in MATLAB. I hope you enjoyed this tutorial. If you face any sort of problem you can ask me in comments anytime without even feeling any kind of hesitation. I will try my level best to solve your issues in a better way, if possible. In my next tutorial I will explain you that how to Calculate the Values of the Trigonometric Functions in MATLAB. I will explore MATLAB further in my later tutorials and will share all of them with all of you as well. So, till then, Take Care :)

DC Motor Projects

Hello everyone! I hope you all will be absolutely fine and having fun. Today, I am going to share a list of tutorials on DC Motor Projects using different software e.g. Arduino, Matlab and NI LabVIEW. I have already shared these tutorials but they are posted randomly. So, today I thought that I should combine all those tutorials into a single one. So I am going to share the links of all of those tutorials in this tutorial so that it may be helpful for engineering students or anyone who wants to visit. This tutorial will help you to visit all of my tutorials related to DC motor control. The links of all the tutorials will be given and you will be able to download the desired tutorial from the corresponding link. I will make separate sections for each software to control DC motor. In each section all the possible controls of DC motor will be given in detail. If you have any sort of problem, you can ask in comments. I will try my level best to solve your issues. In today's tutorial, I have simply combined all the DC Motor Projects posted on our blog. I will update this list in future. So, let's get started with DC Motor Projects:

DC Motor Direction Control - DC Motor Projects

In this section of DC Motor Projects, I will provide you the list of the tutorials in which I have already controlled the direction of the DC motor using three different software e.g. Arduino, Matlab and NI LabVIEW. I have used the same hardware and Arduino source code in all of these tutorials. In case of Matlab and NI LabVIEW I have sent commands through the serial monitor towards Arduino and hence the whole system works. So, let's get started with these DC Motor Projects:
1- DC Motor Direction Control using Arduino
In the tutorial DC Motor Direction Control using Arduino, I have interfaced a DC motor with Arduino UNO board to control its clockwise and counter clockwise direction. I have used a motor controller named as H-Bridge to control the direction of DC motor. It can simultaneously control two DC motors. The algorithm was very simple. Commands for clockwise and counter clockwise rotation are sent through the serial monitor of Arduino software. Its one of the basic DC Motor Projects. These commands are then passed to the motor controller and then it decides the direction of rotation of DC motor after manipulating the Arduino commands. Direction of DC motor can be reversed by simply changing the polarity so L298 controls the direction of the DC motor by continuously making its pins low, high and vice versa.
  • I have posted a detailed tutorial on DC Motor Direction Control using Arduino.
  • You can read that tutorial and download the complete simulation & code by clicking the below button:

Download DC Motor Direction Control Arduino Source Code

2- DC Motor Direction Control using Matlab
In this DC Motor Project, I have done the DC Motor Direction Control in Matlab, I have created a simple Graphical User interface (GUI) in Matlab having three different buttons for controlling the clockwise, counter clockwise direction of the Dc motor and to stop the DC motor as well. Two more buttons are also there on the GUI for opening and closing the serial port. As we press any of the buttons, corresponding command is sent through the serial port from Matlab to Arduino and then Arduino transfers those commands to the H Bridge and hence the entire process gets completed. Pressing the Open Serial Port button, serial port will be opened and we will be able to communicate with the Arduino using serial communication and at the end we must close the serial port in order to avoid the exchange of unnecessary commands being sent through the serial port.
  • You can download the complete simulation here.
  • Download .rar file, extract it and start playing with the simulation. I hope you have enjoyed this DC Motor Project.

Download DC Motor Direction Control Matlab Simulation

3- DC Motor Direction Control using NI LabVIEW
In the tutorial DC Motor Direction Control in NI LabVIEW, I have controlled the clockwise and counter clockwise direction of the DC motor using serial communication between NI LabVIEW and Arduino. Commands like C, S and are sent through NI LabVIEW towards Arduino for clockwise rotation of the DC motor, stop the DC motor and anti clockwise rotation of the same DC motor respectively. There are three different buttons on the front panel of NI LabVIEW. These buttons are used to send commands C, S and from NI LabVIEW to Arduino using Serial communication.
  • You can download the complete simulation here.
  • Download .rar file, extract it and start playing with the simulation.

Download DC Motor Direction Control LabVIEW Simulation

4- DC Motor Direction Control with Arduino in Proteus
In the tutorial, DC Motor Direction Control with Arduino in Proteus, I have designed a complete simulation in Proteus, which will help you in understanding the controlling of DC motor. I have designed DC Motor Drive Circuit in Proteus ISIS. for the DC Motor Direction Control. I have provided the complete simulation and the source code for DC Motor Direction Control in Proteus but I would recommend you to design it on your own, it would be better for you. So, when you send the character C on serial terminal then the motor will rotate in clockwise direction and when the character sent through the serial terminal is A, the motor will rotate in counter clockwise direction and will stop when the character S is sent.
  • You can download the complete simulation here.
  • Download .rar file, extract it and start playing with the simulation.

Download DC Motor Direction Control Proteus Simulation

DC Motor Speed Control - DC Motor Projects

In this section of DC Motor Projects, I will provide you the list of the tutorials in which I have already controlled the speed of the DC motor using three different software e.g. Arduino, Matlab and NI LabVIEW. I have used the same hardware and Arduino source code in all of these tutorials. In case of Matlab and NI LabVIEW I have sent commands through the serial monitor towards Arduino and hence the whole system works. So, let's get started with these DC Motor Projects:
1- DC Motor Speed Control using Arduino
In DC Motor Speed Control using Arduino, I have actually used the concept of Pulse Width Modulation (PWM). For this purpose, I have used PWM pins EnA and EnB of L298 motor control to control the speed of the DC motor. PWM basically control the electronic pulse duration. When the state of the PWM pins of L298 motor controller is high, the output power will be supplied. I have controlled the speed of the DC motor by turning applied voltage on and off. Duty cycle is the main factor while controlling the speed of the DC motor. When the duty cycle is long i.e signal is power is supplied for a long time, Dc motor will rotate at fast speed and vice versa. Usually the PWM duty cycle is less than 90%. I have also printed the executed commands on LCD for this project.
  • You can download the complete simulation here.
  • Download .rar file, extract it and start playing with the simulation.

Download DC Motor Speed Control Arduino Source Code

Note:

2- DC Motor Speed Control in Matlab
In DC Motor Speed Control in Matlab, I have also created a GUI in Matlab having two extra buttons as compared to the GUI of DCMotor Direction Control in Matlab. One for continuously accelerating the speed of the DC motor and the other for continuously deaccelerating the speed of the same motor. As we press any button, corresponding command will be sent through the serial port from Matlab to Arduino using serial communication. The logic created is pretty simple, the speed of the motor will accelerate continuously as many time we press the button and if the maximum speed is reached, motor maintains the same speed even we continue to enhance its speed. Same procedure will be followed to reduce the speed of the DC motor.
  • You can download the complete simulation here.
  • Download .rar file, extract it and start playing with the simulation.

Download DC Motor Speed Control Matlab Simulation

3- DC Motor Speed Control using NI LabVIEW
In DC Motor Speed Control in NI LabVIEW, I have have placed five different buttons on the front panel to control the direction as well as the speed of the DC motor. By pressing the Accelerate button again and again speed of the DC motor will increase in proportion to the number of times the buttons is pressed. Similarly, by pressing Deaccelerate button again and again the speed of the DC motor will decrease in proportion to the number of times the button is pressed. First of all you need to press the Start button in order to start the serial communication between NI LabVIEW and Arduino. After pressing it you will be able to send the commands serially from NI LabVIEW towards Arduino.
  • You can download the complete simulation here.
  • Download .rar file, extract it and start playing with the simulation.

Download DC Motor Speed Control LabVIEW Simulation

4- DC Motor Speed Control with Arduino in Proteus
In the tutorial DC Motor Speed Control using Arduino in Proteus, I have controlled both the direction as well as the speed of the DC motor. For the direction control of DC motor the functionality remains the same as it was in DC Motor Direction Control with Arduino in Proteus but for the speed control, I have placed an Light Dependent Resistor (LDR) sensor in the simulation and depending on the value of the LDR sensor the speed DC motor will either increase or decrease.
  • You can download the complete simulation here.
  • Download .rar file, extract it and start playing with the simulation.

Download DC Motor Speed Control Proteus Simultation

This is all from the tutorial DC Motor Projects. I hope you all enjoyed this tutorial. If you face any sort of problem you can ask me anytime without even feeling any kind of hesitation. I will try my level best to solve your issue in a better way, if possible. I will explore Arduino, Matlab and NI LabVIEW further in my later tutorials. Till then, Take care :)

Declaration of Variables in MATLAB

Hello everyone! I hope you all will be absolutely fine and having fun. In the tutorial Declaration of variables in MATLAB, I will elaborate you that how to declare different variables in MATLAB and how to manipulate those variables without assigning them with the values. Before going into the details of this tutorial you must go through Introduction to MATLAB, because understanding MATLAB first is better. This will help you in better understanding of this tutorial. Variable declaration is one of the most important and compulsory steps while writing the code to perform any task. Without the declaration of the variables we can not proceed further to perform our task properly. So, if we want to do the different tasks in a proper way we must need to declare the variable before doing anything in the code. Once the variables have been declared, we can proceed further to explore the desired task.

Declaration of Variables in MATLAB

Here, in the tutorial Declaration of variables in MATLAB, I will show you that how the variables can be declared in the MATLAB and how to manipulate them without assigning them with the values. The command syms is used to declare the different variables in the MATLAB.
  • Here, I will show you that what happens if you have not declared the variables.
  • The error is shown in the figure below, when you have not declared the variables.
  • I have written an equation having three different variables named as f,t and r without declaring these variables.
  • MATLAB has shown an error on the command window as undefined function or variable.
  • So the error shown in the above figure shows the desired results can not be obtained without declaring the variables first.
  • Now, I am going to declare all the variables first and will then manipulate them.
  • The declared variables are shown in the figure below.
  • Since I have declared all of the variables now which are being used in the equation.
  • So, now I am going to manipulate them and going to observe the results.
  • The result of the addition of the two variables, which is stored in the third variable, is shown in the figure below.
  • The above figure shows the result of the addition of the two different variables in the form of an equation.
  • The result has been obtained because all of the variables has been declared first, i.e. declaration of variables plays a very important role while writing an algorithm to perform any task either simple or complicated.
  • You can also see all of the process in the video given below:
So, that is all from the tutorial Declaration of Variables in MATLAB. I hope you enjoyed this tutorial. If you find any sort of problems you can ask me in comments without even feeling any kind of hesitation. I will try my level best to solve your issues in a better way, if possible. In my next tutorial I will explain you that how to create an m.file in MATLAB. I will further explore MATLAB in my later tutorials and will share all of them with you as well. So, till then, Take Care :)

Introduction to MATLAB

Hello everyone! I hope you all will be absolutely fine and having fun. In this tutorial, I am going to give you a detailed Introduction to MATLAB. I will explain in detail, step by step procedure of using MATLAB for the first time. First of all, I would like to tell you a bit about the MATLAB software. MATLAB basically works on matrices and it is an excellent software for different kinds of simulation based projects as well as hardware based projects and specially, it is good for the Engineering Projects. MATLAB can be used for the manipulation purpose in order to obtain the proper results. It is very easy to use this software and most of the students prefer to use this software for their projects. So, this shows that MATLAB is a user friendly software as well. MATLAB has a very wide range of applications. It can also be used for the real time projects. Robotics, image processing and medical related projects are its major applications. You should also have a look at How to Create GUI in MATLAB. So, let's get started with Introduction to MATLAB:

Introduction to MATLAB

So, in the Introduction to MATLAB, I will show you the step by step procedure about how to use the MATLAB software for the first time.
  • As you open the MATLAB software, a new window will be appeared on your screen.
  • The window is shown in the figure below.
  • The above window is the starting window which appears on the screen when you open the MATLAB.
  • After sometime, you will be able to see another window on the screen.
  • The second window is shown in the figure below.
Sections of MATLAB
There are six basic section of the MATLAB and understanding them is essential part of Introduction to MATLAB. The names of all of these sections are given below.
  • Current Folder
  • Command Window
  • Workspace
  • Command History
  • View or Change Directory
  • Help Section
Current Folder is the first section of the MATLAB’s front window at the left side of the window. It displays the files that has already been saved. You can open the files that are already saved somewhere in your PC or laptop.
  • The current folder section is shown in the figure below.
Command Window is the second section and is used to show the results of the entire source code. If we want to observe the results on the command window, we must not put a semicolon after the statement then. If there is a semicolon at the end of the statement, result of that statement will not be shown on the command window.
  • The command window section is shown in the figure below.
Workspace is the third section of the MATLAB’s front window which shows all the variables that are used while writing the complete algorithm.
  • Workspace section is shown in the figure below.
Command History is the fourth and the last section of the MATLAB’s front window. It shows all of the commands that have been used in the entire algorithm.
  • The command history section is shown in the figure below.
View or Change Directory helps us to view the directory or the complete destination of the file that is opened in the MATLAB. You can also open a new file by changing its directory.
  • Directory box is shown in the figure below.
Help Section is also an amazing tool of the MATLAB. It provides help regarding of the command or any other thing related to MATLAB. By typing the thing which is not clear, you will be able to find a lot of help.
  • The button to open the help section is shown in the figure below.
  • As you press this button a new named as help will be appeared on your screen to help you.
  • The help window is shown in the figure below.
  • So that was the brief discussion about how to getting started with the MATLAB.
So, that is all from the tutorial Introduction to MATLAB. I hope you have enjoyed this tutorial. If you find any sort of problem in introduction to matlab, you can ask in comments anytime without even feeling any kind of hesitation. I will try my level best to solve your issues in a better way, if possible. In my next tutorial I will elaborate the Declaration of Variables in MATLAB and how to manipulate them without assigning them with the values. Moreover, you should also have a look at How to Create m file in MATLAB. I will further explore MATLAB in my later tutorials. So, till then, Take Care :)
Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir