Write a script that will read from a file x and y data points in thefollowing format:

x 0 y 1
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 a point number, a space, the characters‘(x,y)’, a space, the x value, a space, and the y value. First, create the data file with 5lines in this formatand save it as xypointts.dat. The script will attempt to open the data file and error-check to make sure it was opened. If so, it uses a forloop and fgetlto read each line as a character vector. 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.

Answer :

Answer /Explanation

load hw92.dat

FID = fopen(file, 'r');

if FID == -1  

   fprintf('ERROR CANNOT OPEN FILE TO READ!');  

else

   fclose(file);

The we have:

datacell = textscan(FID, 'x%fy%f', 'CollectData', 1);

xycoords = datacell{1};

x 0 y 1

x 1.3 y 2.2

x 2.2 y 6

x 3.4 y 7.4

x 4.2 y 5.5

x 4.4 y 4.5

x 6.2 y 7.8

x 7.7 y 11.1

x 8.2 y 11.5

x 9.9 y 15.2

x 7.2 y 9.5

x 8.9 y 12.5

end

MrRoyal

Scripts are simply programs interpreted by another program

The script written in Python, where comments are used to explain each line is as follows:

# This opens the file for read operation

file1 = open("myfile.txt","r+")

#This reads the file

#This prints the content of the file

print(file1.read())

Read more about Python programs at:

https://brainly.com/question/16397886

Other Questions