Formatted File Output In the past we saw how to save variables to files using save. This created files that were in MATLAB's own format or saved matrices on top of each other. Often, we want to write to a file in a specific format. For example, if we have a data file, we may want the first row of the file to specify what each column represents. We can do this using some extra functionality of fprintf. First, we need to open a file for writing. fileID = fopen(filename,permission); The first argument is a string that is the filename of the file to open. The second argument sets the type of access we want for the file. Use 'r' for read access, 'w' for write access (deletes current contents), and 'a' to append to a file. More options available, check documentation. When we're done with a file, we can close it using fclose(fileID) Once we've opened a file for writing (or appending), we can use fprintf to write to it. fprintf works the same as before, except now we specify a file as the first argument. fprintf(fileID, formatSpec, A1, A2, ..) Recall: formatSpec describes format of output Can contain literal text, escape characters, places to insert values To insert values – use conversion character %d – integer (signed) %f – floating point in fixed notation, %e – in exponential notation %c – single character string %s - single string Before conversion character can have Field width, e.g., %12d Precision, e.g., %10.4f means field width of 10, 4 spots to right of decimal Flags, e.g., '-' does left justify Can output vector of strings Can output entire matrix at once (but formatting is hard) Show example for measurement data.