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

matlab ques 1a) Write a script that will read from a file x and y data points in

ID: 3767349 • Letter: M

Question

matlab ques

1a) Write a script that will read from a file x and y data points in the following format:
x0y1
x 1.3 y 2.2

x 2.2 y 6
x 3.4 y 7.4
The format of every line in the file is the letter ‘x’, a space, the x value, space, the letter ‘y’, space, and the y value. First, create the data file with 10 lines in this format. Do this by using the Editor/Debugger, then File Save As xypts.dat. The script will attempt to open the data file and error-check to make sure it was opened. If so, it uses a for loop and fgetl to read each line as a string. In the loop, it creates x and y vectors for the data points. After the loop, it plots these points and attempts to close the file. The script should print whether or not the file was successfully closed.

b) Modify the script from a. Assume that the data file is in exactly that format, but do not assume that the number of lines in the file is known. Instead of using a for loop, loop until the end of the file is reached. The number of points, however, should be in the plot title.

Explanation / Answer

x = [];

y = [];

fid = fopen('xypts.dat');

count = 0;

if fid == -1

else

end

if fclose(fid) == -1

else

end