Experiment 1 1
Experiment 1 1
Experiment 1
Aim: Introduction to MATLAB
Theory:
1. Assigning value to a variable: We can assign value to any variable using the
‘=’ symbol.
Syntax: a=5; OR a=5
If you omit the semicolon at the end of a command, the result is displayed
immediately in the command window.
2. Initializing an
array: In MATLAB, an array is
a fundamental data structure that can store
values of the same type. Arrays can be one-
dimensional (like vectors) or multi-dimensional
(like matrices). Initializing an array involves
allocating space for the array and assigning
values to its elements.
Syntax:
a=[1,2,5,6,7] Row Vector
b=[2;4;3;8;9] Column Vector
c=[1, 2; 3, 4] Matrix
3. Prebuilt Functions:
3.1.Zeros: Creates an array of zeros.
3.2.Ones: Creates an array of ones.
3.3.Rand: Creates an array with random values
between 0 and 1.
Syntax:
a=zeros(3,3)
b=ones(3,2)
c=rand(2,3)
5. Element-wise Operator: To
multiply each element of an array
individually in MATLAB, you can
use element-wise multiplication.
The element-wise multiplication
operator is (.*).
Same is applicable for all other
logical operators as well.
Syntax:
a=[1,2,5,6,7]
b=[2,4,3,8,9]
c=a.^2+b.*3