MATLAB Functions

Set Functions
‡ For random generations we can use rand(2,5) randn(2,5) We can compare numeric and character values using isequal function. a=[1 2 3 4 5], b=[1 2 3 4 5] ans =1 isequal(a,b) returns 1 if both are equal else 0

Set Functions
>>a = Infosys >>b= Infosys >>isequal(a,b) ans =1 >>a=(2:2:8;4:2:10) >>a= 2 4 6 8 4 6 8 10 >>Unique(a)

Set Functions
>>Unique(a) >>Ans =2 4 6 8 10 >>C={ sania , Britaey , Dixie , Sania , Faith }; >>Unique(c); >>Ans= Britaey , Dixie , Sania , Faith >>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)

1.Find your age using date function 2.Display relevant message like Good Morning or Good Evening based on the input time

Sign up to vote on this title
UsefulNot useful