Education

How To Use MATLAB Assignment Operator in MATLAB Coding?

Hello, everyone today we are going to talk about the basics of fat lab so after you download MATLAB assignment the very first thing that you’re going to want to do if you’re a complete beginner is learn about the assignment operator. In addition, basic defines so in programming we want to assign a value to a variable so in this case let’s take x I want to assign the value of 2 to x so 2 x equals 2 but the equal sign is not the same as a mathematical equal sign.

In this case we refer to it as the assignment operator so I’m assigning the value of 2 to x so now if I wanted to use the value of x whatever x represents later in the code and, I want to say x plus 2 we see that now y equals 4 because it took 2 from the x and added 2 on top of it. I can also always change the value of x so now I change the value of x to four now y equals six really quick if you see.

How this equal sign is highlighted:

How this equal sign is highlight right here and here that means that we are not suppressing it with a semicolon which is why it’s showing up in the command window like this. So if I was just to do this and this then we wouldn’t see anything but we can still see it over here on the side where x equals 4 and y equals 6. We can change this to whatever we want if we wanted this to be 10 we see that x is 10 and y equals 12. the same thing happens if we want to define a variable as a string.

So if i wanted to var is my variable and I will define it as name if you see up here string var is now the string name now if I was to take out these quotes let’s see what happens. It’s looking for a function called name which does not exist a function or a variable called name these quotes tell MATLB assignment that it’s a string and not a variable there’s also double quotes and those are string arrays.

What MATLAB assignment did was it converted each letter:

But we’ll talk about that later this is just kind of the basics same thing happens here so if I wanted to do z equals string bar plus x what do we get. I actually want to see that so I’m not going to suppress it with a semicolon and you see that equal sign highlights again so here we get an array 88 107 119 111 what does that mean so because string bar is a string obviously but we’re adding a number to it.

So what MATLB assignment I converted each letter into a value so if we look at the ascidia table you can look this up on google each letter each symbol has a value. So what MATLAB assignment did was it just took the value of n took the value of a took the value of m and took the value of e and added um x or in this case 10 10 or x to each uh value that that letter represents which is why we get 88 107 119 111. We’ll talk more about arrays later um but this is just kind of to see why this doesn’t work we there’s really no point of doing that that’s not something that we’re really going to see.

I’m defining a variable:

So yeah those are kind of the basics of just defines so in my head I’m defining a variable right I’m defining x as 10. This is kind of just like algorithmic um to make sure that when you code you always kind of want to put comments especially when you’re a beginner it kind of helps you understand. What you’re doing and if you’re turning something it helps your professor understand what you’re trying to do and algorithms are just a very good coding habit.

MATLAB assignment the algorithm which or the comments would just be with the percent sign so percent time definably using x12 and then this one would be define string bar as and now I’m putting this. After but it should have been put before but yeah those are the very basics of MATLAB assignment.

Assignment operator within the MATLAB assignment:

We can use the assignment operator within the MATLAB assignment in all other languages like c python or java usually is equal to sign is consider as the assignment operator because on one side of this assignment operator. Or the sign of equality we need to write the variable and here variable is usually or always you can say that an alphabet or any word like a b c or anything like that.

Then there is an equality operator or assignment operator and now we can write like 18. So here we can see that now 18 is assign to the variable a or simply assignment means the storing of variable that is 18 into the a or assigning the value 18.

We will write welcome:

To the variable a okay then uh we will write class of a so in order to find it what type of data it contains when we will enter it will tell us it is double. Because double contains both the decimal integer and flow type data types like it can be like one two three or like 34 or any number and like 9.8 like. It can it can contain some sort of decimal in it now we will uh write same a is equal to this and,

We will write welcome so what it means now welcome is actually a string or character array so you need to learn that math label auto assign the data type. That is the class of a will give us the character why this so because it is not the integer or numeric or decimal type data type it is the character array so that is why the MATLB assignment is giving us the c-h-e-r-r character again. If you want to write a is equal to unsigned integer 8 of 4 then here obviously a is contain now containing four due to this assignment operator.

You may also read: How To Plan A Trek With These Simple Tips?

Leave a Reply

Your email address will not be published. Required fields are marked *