Variables are data storage space for numeric or string values.
The string is a basically text the main benefit of using variables instead of directly
using the data themselves is that we can reuse them by calling the variable names when needed.
Variable names are typically English alphabet A to Z either lowercase or uppercase or combinations of English
alphabet numeric number and underscore. Here are a couple of examples for
creating variables in this diagram. My English alphabet "a" is a variable name
and numeric number 2 is the numeric number that I would like to save in the
data storage space. I can use "b1" as a variable name to hold a numeric number 3.
Next, I can use a underscore text as a single word for a variable name to hold
"Octave" as string or text values. Let's practice how to create variables. Here is
a basic rule to follow to create the variables. First, you need to start with
the variable name followed by equal sign, then type expression afterwards.
The expression can be either a numeric number, mathematical expression, string
and another variables or a combinations of them. For example, to create a variable
"a" to hold a number two you should type "a" equal sign followed by 2 and hit enter
in the command window. If successfully created it automatically prints a equals
2 below if you don't want to immediately print you can use the semicolon at the
end of expression such as a equal to 3 followed by semicolon at the end so you
don't see any result in the screen but it creates the variable a entirely you
can check what data has been saved by simply typing a followed by Enter key
if you try to print the variable name that has not been created before,
you will get the error message. For example, if you simply type "b" which never been
used before and you get an error message as undefined. Octave cannot print the
undefined variable. You can also a mathematical expression to create
a variable I would like to create a variable "b" to assign the result of one
plus three over a to type "b" equals sign followed by 1 plus 3 divided by 2.
You can create a variable "c" by assigning
the data given in the existing variable "b". To do this, type "c" equals sign followed
by "b". Also, you can create a variable "d" by adding 1 to the existing variable "b".
To run this operation, you can type "d" equal sign followed by "b" plus 1. You can use
the same variable in the left and right sides of equal sign just like "a" equals
to "a" plus one the "a" on the left side of the equal sign is considered as a new
variable name even though you already had it the "a" on the right hand side is "a"
considered as the expression. Basically, this expression is translated as we
create the variable a by assigning a plus one in this case we already have
three in the variable "a" and we add 1 to 3 to update the variable "a" with
4. In other words, we replace "a" on the left side with 4. This expression is
very useful to replace it by itself without creating a new variable, when we
write a code in the future, so please keep in mind. So far, we created four
variables "a" through "d" to check what variable names has been used so far
there are a couple of different ways. First, we can simply types "who" "w""h""o".
You can see the list of variables that has been created so far we have "a" through "b"
and "ans". You can also type "whos" add "s" at the end. To check some more details
including the data size, memory use, and precision. You can also check the
workspace on the left side of the main window it shows the variable names and
given data. To delete the variable, you can use "clear" followed by the variable
names that you want to delete. For example, you can clear variables "a" and "b"
by typing "clear" space "a" space "b". Check it in the workspace or a type "who" see what
happened. You can also delete all the variables using "clear all".
There are a few things that you need to be careful about variable names.
First, the variable name must not include special characters or any empty space.
For example, "a" exclamation mark "bc" does not work because of exclamation mark "a" space
"bc" cannot be used because of space between "a" and "b". "1abc" does not work
either since you cannot start with the number for the variable name.
Variable names are case sensitive and "abc" all lowercase is different from "Abc" with
the uppercase "A", so you need to be careful about this to create a variable
name for text. You should use single quotation mark. Your text should be
enclosed by two single quotation mark. For example, you can create a underscore
text for "Octave" without using the single quotation mark you will get the error.
It says "undefined" meaning that it considers "Octave" as a variable name,
but it has not been used before, so it gives us an error.
in summary you have learned about variables focusing on single element. Thanks for watching this video
and please subscribe my channel, if you haven't done it yet. Thumbs up, if you
enjoyed. Please feel free to share your thoughts in the comment section below
see you next time