Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Read the documentation for the functional forms given below and write a brief

ID: 3820387 • Letter: 1

Question

1) Read the documentation for the functional forms given below and write a

brief description (2-3 sentences) for each one. Each description should discuss parameters, return values (if any), and where the function might be used. Make sure to cite your sources and state your responses in your own words.

a) TF = strcmp(s1,s2)

http://www.mathworks.com/help/matlab/ref/strcmp.html

b) fileID = fopen(filename,permission)

http://www.mathworks.com/help/matlab/ref/fopen.html

c) r = rand

http://www.mathworks.com/help/matlab/ref/rand.html

d) fprintf(fileID,formatSpec,A1,...,An)

http://www.mathworks.com/help/matlab/ref/fprintf.html

e) fclose(fileID)

http://www.mathworks.com/help/matlab/ref/fclose.html

Explanation / Answer

a) TF = strcmp(s1,s2)

tf = strcmp(s1,s2) compares string1 and string2
if the two strings are same this function returns true other wise false

if true returns 1
if false returns 0

it returns the logical data


b) fileID = fopen(filename,permission)


opens the file with the type of access specified by permission. like fileID= fopen(filename,"w")// here w is writing permission

so it returns the file identifier, we can pass this file identifier to read data


c) r = rand

it returns a single uniformly distributed random number in the interval (0,1)

example : num = rand() % 100 + 1;// generating 0 to 100 random numbers

d) fprintf(fileID,formatSpec,A1,...,An)

it applies the formatSpec to all elements of arrays A1,...An in column order
and writes the data to a text file by using fileID (file identifier)

fprintf uses the encoding scheme specified in the call to fopen.

Ex: fprintf(fileID,'%6s %12s ','x','exp(x)');

e) fclose(fileID)

it closes an open file. fileID is an integer file identifier obtained from fopen.


EX:
FILE *f1;
fclose(f1);// closing f1