Programming by MATLAB 2
Programming by MATLAB 2
The data type you assign must match with the data. For example (uint16) does not accept
negative values, if user does, that MATLAB will assign 0 to the variable instead of the
negative number.
1.2. Characters and Strings
• In MATLAB, char refers to character data type and a row of a
characters is called string.
• Each char type needs 2 bytes to store in computer memory.
• To declare a variable of type character, just use (char) before the
variable name:
1.2. Characters and Strings
• Also user can define char type by holding variable value between
two quotations.
1.2. Characters and Strings
Example:
y=x/2;
y_val=num2str(y);
• MATLAB has many reserved names and user must not use it to name his
variables, some of these reserved names are :
(For, end, if, while, function, return, elseif, case, otherwise, switch, continue, global,
break, try, catch).
2.1. Variables
MATLAB Special Variables
Special variables have some value that are already
reserved by MATLAB. the following table list the mostly
used one:
2.1. Variables
MATLAB Special Variables
• As mentioned that user shouldn’t give names to his
variables similar to MATLAB special variables, this
causes overriding and lost its original value, as an
example to overriding (pi) value:
Note: Restarting MATLAB will reset the special variable to its original values.
3. Some Commands
1. clc command
This command cleans the command window of matlab but does not
delete variable
value from the memory.
2. clear command
Clear command used to delete variables permanently from the
memory and it can be
used to clear a specific variable, to do that just type clear followed by
variable name
in command window.
Or you can delete all variables from workspace window by typing only
clear in
command window.
3. Some Commands
3. who and whos commands
who command return names of the variables in workspace and whos
return a list of
properties for a variable include its size, bytes, class and attributes.
3. Arithmetic Operations.
1. Parentheses
2- Power operator executed firstly.
3- Multiplication and division.
4- Addition and subtraction.
3. Arithmetic Operations.