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

MATLAB Language! Practice 1: % Objective: Open a file, deal with the data using

ID: 644918 • Letter: M

Question

MATLAB Language!

Practice 1: % Objective: Open a file, deal with the data using string-related function, and close a file. Example: we have a file looks like this: Feb-01-2015 72 Feb-02-2015 68 Feb-03-2015 69 This file records the each day's average temperature at San Diego for the whole February in 2015. The first column is the date, followed by the average temperature of each day. Write a script that will first attempt to open the file. If the file open is not successful, an error message like ''File open fails!'' should be printed. If it is successful, the script will read the data into strings one line at the time, save the temperature into a vector, and meanwhile print each day's temperature in the following format: The temperature on Feb-01-2015 is 72 F. After finishing reading the file and printing, close the file and check whether the file is closed successfully. Finally, calculate the average temperature of the February, and print it like this: The average temperature of the February at San Diego is 70 F.

Explanation / Answer

load temparatire.dat;       
   dateis= PDXprecip(:,1);     % copy first column of PDXprecip into month
   temp = PDXprecip(:,2);    % and second column
   disp('The temparature on'+dateis+'is'+temp);