Construct and save a formatted sensor record

A technician needs to construct one sensor record in memory, write it to a text file, and close the file. The following MATLAB statements have already executed successfully:


MATLAB
sensor = 'B7';
voltage = 3.25;
fid = fopen('sensor_record.txt','wt');


The variable fid holds a valid file identifier. Enter only the MATLAB function name needed for each operation, replacing NAME in the indicated statement.

  • In line = NAME('sensor=%s,voltage=%.2f V\n',sensor,voltage);, replace NAME with to return the formatted record as a character vector in memory.
  • In NAME(fid,'%s',line);, replace NAME with to write the complete record to the open file.
  • In NAME(fid);, replace NAME with to close that file after writing.

Assume all file operations succeed. The sequence \n requests a line break when interpreted by the formatting function.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Data Files and Character Strings Questions: