Professional Documents
Culture Documents
Set Functions
• For random generations we can use
rand(2,5)
randn(2,5)
>>a=1:9 =1 2 3 4 5 6 7 8 9
>>b=2:2:9 = 2 4 6 8
>>ismember(a,b) – If available ‘1’ else ‘0’
>>ans=0 1 0 1 0 1 0 1 0
Set Functions
>>ismember(b,a)
>>ans=1 1 1 1
>>union(a,b)
ans= 1 2 3 4 5 6 7 8 9
>>intersect(a,b)
ans= 2 4 6 8
Date Functions
>>now
ans = 7.3456e+005
>>datestr(now)
ans =23-Feb-2011 12:08:05
>> datevec(datestr(now)) – Covert into array
ans = 2011 2 23 12 08 05
[yr,mo,day,hr,min,sec] format
>>[d,w]=weekday(now)
>>d = 5 w = Thu
>> calendar(2011,2)
Feb 2011
S M Tu W Th F S
0 0 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 0 0 0 0 0
0 0 0 0 0 0 0
Lab Exercises
• Programs in functions
1.Generate random numbers using rand() and randn() functions
2. Check with isequal() function
a=[1 2 3 4 5], b=[1 2 3 4 5]
c=[1 2 3 4 5], d=[1,2,5,6,7]
a = ‘Infosys’ b=’Infosys’
c =‘Infosys’ d=‘infocmp’
3. a=(2:2:8;4:2:10) –Find unique(a)
4. C={‘sania’,’ Britaey’, Dixie’,’ Sania’,’ Faith’} Find Unique(c)
5. a=1:9 b=2:2:9 Find ismember(a,b) and ismember(b,a)