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: 3567576 • 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.

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)

strcmp() method is used for the comparison operation. Consider the statement, TF=strcmp (S1, S2). In this statement, S1 and S2 are the two strings which are passed to the method strcmp() for comparison. TF is the variable of data type logical. Strings S1 and S2 compared for their identity. If these strings are identical by size and content, TF will return true or 1, It they are not identical, TF will return 0 or false.

This function can be used in the situations when the comparison process has to be done.

b)

Consider the function fileID = fopen(filename,permission). This function opens the file with the filename mentioned as parameters and the type of the access will be specified by permission. If a file cannot be opened, the fileID value will be -1.

This function can be used in the situations when a file has to be opened with a specified permission which restricts the access of the file.

3)

rand are pseudorandom numbers which are uniformly distributed. r = rand will return a pseudorandom scalar number which is drawn on the open interval (0, 1) from the distribution which is uniform.

In the situations when there is a requirement for producing random numbers, this can be used.

4)

fprintf() is the function which is used to write data to a text file. Consider the function   fprintf(fileID,formatSpec,A1,...,An). This will apply the formatSpec to all the array elements of the arrays A1,...,An. This is done in the column order and the data will be written to a text file. fileID is the parameter which is the integer file identifies.

This function can be used in situations when there are many arrays and all of them must be maintained in same format.

5)

fclose() function will be used to close one or more files which are open. fclose(fileID) will close the file which is open. fileID is the parameter which is the integer file identifies.

This function can be used to close all or one file which is open.