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 :)
I am Syed Zain Nasir, the founder of The Engineering Projects (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. My Google Profile+Follow