Introduction To MATLAB

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 37

Introduction to MATLAB

A complete step by step tutorial on Getting Started with the


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, lets 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 MATLABs 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 MATLABs 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 MATLABs 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

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
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. Its 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 dont 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

How to create a GUI in


MATLAB ?
Hello friends, I hope you all are fine and enjoying life. Today i am
going to share a new project tutorial which is How to create a GUI in MATLAB ? First of all,
lets have a little introduction that what is meant by GUI? How it is created and what are the
uses and applications of GUI? GUI stands for Graphical User Interface. We all know the
basics of MATLAB that it is used for creating complex algorithms and to create Simulink
simulation, but we dont know that it aalso has another feature which is to create GUIs. The
algorithms developed in MATLAB works on the background and do their tasks while
MATLAB also emphasis on the user interaction thats why it has also provided us with GUI
so that we can create a user friendly front end interface for our algorithm.
So, in todays post, we are gonna have a look at How to create a GUI in MATLAB so that we
could also give a user friendly front end to our algorithms. MATLAB GUI has an extensive
database with a lot of functionalities, which I cant cover in one post but atleast today, I will
make you able to create a simple GUI and will also explain How to control buttons and edit/text
boxes etc. After performing this tutorial, you will be able to try GUI on your own.
So, today we will create a simple project in which we will create a simple GUI as shown in
below image. The functionality of this GUI will be that when you click on this START button
then the text,you have written in the white edit box will appear at the text box above, as shown
in figure below. Lets get started with the implementation of this GUI. Follow the steps carefully
and ask in comments if you got into any trouble.
You may also like to read:
Protect Code in M File
Protect Simulink Design in Matlab
You can download this GUI by clicking on the below button, but first read the tutorial
completely aand try to pratice it by yourself,dont just download the run the applicationas it
wont give you any help.
Download Simple GUI Project in MATLAB
https://www.theengineeringprojects.com/2015/05/www.theengineeringprojects.com/Examples/Howto
CreateaGUIinMATLAB.rar

HOW TO CREATE A GUI IN MATLAB ?

First of all, when you will open your MATLAB software then, the first window opened will
look like as shown in the image below.This is the simple workspace of MATLAB, now in
order to open theGUI toolbar, you have to write guide in the workspace as I did below:
After writing the guide in command window, hit ENTER and a new small window will open
up as shown in the below image, from here we will start creating our GUI.

As you can see in this small window, there are two tabs, one tab is named as Create New
GUI, which has the options for creating your GUI for the first time while the second tab is
named as Open Existing GUI, which is used for opening the already designed GUIs and
as we havent designed any GUI yet so we will remain in the first tab and will select blank
GUI from the list and hit Enter.
Then press OK button and as you will complete the action, a new window will immediately
open and it will look like as shown in the image given below:
This is the place where we are gonna create our GUI. The left side toolbar is showing the
controls which we will drag aand drop in the main window and will design our GUI.
Lets first have a look at the left side toolbar controls. On the top left side of the bar, the
first button is to select cursor . Below curser button we have icon of Push Button. Next
to that we have side scroll bar. Then comes Radio Button and Check Box. Then we
have most important buttons which are Edit text bar button and Static text bar button.
Below are also some other buttons and you can also explore them by simply clicking on
them.
Other MATLAB Projects:
Send Data to Serial Port in MATLAB
Speech Recognition using Correlation
DTMF Decoder using MATLAB
Hexapod Simulation in MATLAB
Now we are going to make a very small and simple interface, in which we will first select
a button and then we will select Edit text bar and static text bar and we will make the
arrangement in such a way that, when we will press the button then, data will move from
Edit text box to Static text box.
Now click on the button icon and the next thing which will happen on the window will be
like as shown in the image below:

Now if you want to change the properties of the button, either you want to change its name
or you want to change its setting then, simply double click the button and a new window
will open, which will be as:
As you can see in the above image that a new window has been opened and it has a large
no of options.
To change the name of push button, go to string option and here you can change its
name.
In above image, you can clearly see that, i have replaced the name Push Button by Start.
Now click on the Play icon in the top toolbar which is used to run the GUI. After doing that,
a new window will open, which is shown in the below image:
This new window in above figure is the back end programming of this GUI created
automatically by MATLAB, here we are gonna add all the codes for our ontrols.
Now we want to add a static text box and we will select it from tool bar manually.
And if you again want to change its name then, we will double click on that. Go to slide
option and and write whatever you want to write there.
All this process is shown in the below image:
Now i want to write our official site address, which is www.TheEngineeringProjects.com
.
And when i will press OK button then our GUI window will look like as shown in the below
image:
This time, I have not only changed the name of this text box but have also changed the
font size and color thats why it is appearing now in light blue color and its font size has
also increased. So, now you must have the idea that you can control all the properties and

can make it literaly a new thing. The only thing stopping you is your imagination.
In the same manner we will select edit text box.
Now by doing all this, actually i want to write some data in Edit Text Box and when i will
press Start button then, data will move from Edit Text Box to Static Text Box.
To implement this logic we need to load a function code in Start button. To load the code,
right click on the Start button and a new window will open as shown in the image below:
As shown in the above image when you will go to the view callbacks option and a next
window will open direct to it and then click on the call back button.
After that a new window will open which will be representing the code which has been
uploaded in the Start button.
This window is shown in the below image:
Now code has been uploaded and the very next window which will open, will be of Edit
Text Box .
Here you can write anything which you want to Display in Static Text Box.
So in this window, i am writing my tutorials title, which is How to create a GUI in MATLAB.
It can be seen in the below image:
When you will press Enter then, immediately an-other button will open which will be
representing that our data has been moved to Static Text Box.
As you have seen that our Final Display is same. Which means we have moved data from
Edit Text Box to Static Text Box.
The code added in the button CallBack is as follows:
x = get(handles.edit1,String); %edit1 being Tag of ur edit box
if isempty(x)
fprintf(Error: Enter Text firstn);
else
set(handles.text2,String,x)
end

x = get(handles.edit1,String); %edit1 being Tag of ur edit box


if isempty(x)
fprintf(Error: Enter Text firstn);
else
set(handles.text2,String,x)
end

Have a look at this below video in which we have explained in detail How to Create a GUI
in MATLAB:
Alright Friends, that was all from todays post and i hope you have learned something new.

Dont feel shy to ask anything in comments. Till next tutorial take care !!

How to Clear MATLAB


Windows ???

Hello everyone! I hope you all will be absolutely


fine and having fun. Today, I am going to share my knowledge with all of you guys about How
to Clear MATLAB Windows. If the command window and workspace window are not clear
they present a very complicated look and hence the user feel it difficult to write code on
command window. Here, I have compiled a list of awesome MATLAB Image Processing

Projects so must check them out to get some inspiration.


So, for the ease of the user we need to clear the both window specially the command window
because it contains the entire code for any of the task. Before going into the details of this
tutorial, you should go through Introduction to MATLAB and Declaration of Variables in
MATLAB for the better understanding of this tutorial. If we want to avoid the complications
while writing the code on command window we must need to clear the both command window
as well as the workspace window. If you dont wanna work on Command Windows then you
should have a look at How to Create m File in MATLAB. Anyways, in todays tutorial we are
gonna have a look at matlab clear command window and its quite easy but I must say its
quite handy, especially when you are working on some complex MATLAB Project.. So, now
lets get started with todays tutorial and have a look at How to Clear MATLAB Windows:
HOW TO CLEAR MATLAB WINDOWS ???

In the tutorial, Clearing MATLAB Windows I will show that which commands are required to
use to clear the command window and workspace window In order to avoid the complications
for the user while writing the source code on the command window.
The commands for clearing the command window and workspace window are shown
below.
1. clear all (used to clear the workspace window)
2. clc (used to clear the entire command window)
The command window with some of the commands written on it is shown in the figure
below.

The workspace window having some of the variables is shown in the figure below.
Clearing both the Windows
First of all I will show you that how to clear the workspace window.
Go to the command window and write the command clear all and press
All of the above steps are shown in the figure below.
You will see that all the variables from the workspace window has been removed.
The cleared workspace window is shown in the figure below.

Now go to the command window and write the command clc on it.
The command written on the command window is shown in the figure below.

If you press Enter after writing the command show in the figure above, on the command,
you will see that the command window has be cleared.
The empty command window is shown in the figure below.
So, by clearing both of these window a user can easily make an algorithm without any
complication.
You should also have a look at this video tutorial as well:

That is all from the tutorial, Clearing Command Window and Workspace in MATLAB. I hope
you enjoyed this tutorial. If you face any sort of problem in clear command window matlab,
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

You might also like