Lecture 4
Lecture 4
Programming in MATLAB
Lecture-4: Some Common Functions
size()
A = 1:10
A=
1 2 3 4 5 6 7 8 9 10
B = fliplr(A)
B=
10 9 8 7 6 5 4 3 2 1
Create a random logical matrix
rand()
rand(5)>0.5
ans =
0 1 1 1 0
0 0 1 0 0
0 0 1 1 0
1 0 0 0 0
0 0 1 0 0
Create a random binary vector
rand(1,10)>0.5
ans =
0 1 1 0 0 0 1 0 0 1
Convert vector array into matrix
vec2mat()
mat = vec2mat(vec,matcol) converts the vector vec into a matrix with
matcol columns, creating one row at a time. If the length of vec is not a
multiple of matcol, then extra zeros are placed in the last row of mat.
c=rand(1,10)>0.5
c=
0 1 0 0 0 1 1 1 0 1
d=vec2mat(c,2)
d=
0 1
0 0
0 1
1 1
0 1
input()
X=input(prompt,'s’)
It returns the entered text, without evaluating the input as an expression..
D=double(s)
D=
115 97 110 100 105 112
char(D)
ans =
'sandip'
Assignment-2
Encoding method:
Replace 2nd column with [1st column xor 3rd column]
Replace 4th Column with [2nd column xor 5th column]
Replace 6th Column with [4th column xor 7th column]
All other columns remain the same