Matlab Variables
Matlab Variables
Abeer Qashou
Variables and Assignment Statements
No need for types. i.e.,
int a;
double b;
float c;
Variablename = expression
Note that the variable name must always be on the left, and the expression on the right
Variables
The rules for Variable Names and File Names
The name must begin with a letter of the alphabet (e.g., A2z or a2z )
There are certain words called reserved words can not be used as
variable names.
up to 63 characters
clear: clears all variables, reset the default values of special variables.
2. Character
3. Logical
4. Structured
5. special types.
Numeric Data Types
Store numerical values and are the most
commonly used data types in MATLAB
It includes three (3) sub types:
2- Structures (Struct)
Stores data in named
fields, similar to objects in
OOP.
Syntax
s = struct
s = struct(field,value)
s = struct(field1,value1,...,fieldN,valueN)
s = struct([])
Structured Data Types
3- Tables (table): Array in tabular form whose named columns
can be of different types.
y = dec2base(13, 2);
% y = '1101'
x = base2dec('27', 8);
% x = 23
y = dec2base(23, 8);
% y = '27'
y = dec2base(45, 10);
% y = '45'
x = base2dec('1F', 16);
% x = 31
y = dec2base(31, 16);
% y = '1F'
Operations in MATLAB
Operation is defined as an action performed on data (such
as numbers or matrices) to achieve a specific result, like
performing a calculation, comparison, or modifying the data.
Logical Operations.
Relational Operations.
Others (Set operations, Bit-Wise operations, Special Characters)
Arithmetic Operations in MATLAB
These operations are used to perform basic mathematical
calculations like addition, subtraction, multiplication, division, and
more.
Here are some of the common operations that can be used
with numerical expressions:
Operation Symbol Example Answer
Addition + 5+3 8
Subtraction - 5-3 2
(negation)
Multiplication * 5*3 15
Division / 10/5 2
(divided by)
Division \ 5\10 2
(divided into)
Exponentiation ^ 5^2 25
(Power)
Numbers can also be shown usin
scientific or exponential notation
Arithmetic (Math) Operation Precedence
Not Equal to ~= Compares whether two values are not 5~=3 1 (true)
equal.
2 Exponentiation.
4 Multiplication, division.
5 Addition, subtraction.
8 (lowest) Logical OR ( | ).
Scalars, Vectors, and Matrices
A scalar is a single number (one element).
Example: