A pump test file uses semicolons between fields and commas as decimal separators. Its header is SampleID;Flow_L_min, and its two data records are 0014;1,25 and 0015;0,75. Flow values are in L/min, with no thousands separators.
The following MATLAB configuration has already identified the two variable names correctly:
opts = detectImportOptions("pump.csv", "Delimiter", ";"); opts = setvartype(opts, "SampleID", "string"); opts = setvartype(opts, "Flow_L_min", "double");
Which additional statement explicitly makes the numeric interpretation match the file before executing T = readtable("pump.csv", opts);?
opts = setvaropts(opts, "Flow_L_min", "DecimalSeparator", ",");
opts = setvaropts(opts, "Flow_L_min", "ThousandsSeparator", ",");
opts.Delimiter = ",";
Unlock full course notes by signing up
Import pressures with a missing reading
A pressure logger's measurement column has been imported into MATLAB as this string array:
The numeric entries are pressures in kPa. The logger documentation defines NA as a missing reading. Calculate the arithmetic mean of the available readings, excluding the missing entry. Give your answer in Pa, to one decimal place.
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:
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.
Repair an import that loses meaning
A materials laboratory defines 0031 and 31 as distinct part identifiers. A comma-delimited source file has the following contents:
The extension values are in mm. NA means that no reading was recorded, while 0.00 is a genuine measured zero.
An import pipeline reads PartID as double, converts those numeric IDs to strings, and replaces missing extension values with zero. The original file remains available. Which repair preserves both distinctions required by the source?
Audit the records written by fprintf
An engineer intends to export three measurements, with time in seconds in the first column and voltage in volts in the second column. The engineer runs this MATLAB code without rearranging the data:
Assume all file operations succeed. Determine what the file actually contains, even if its header assigns misleading meanings to the values.
Report the first numeric field of the second data record as a time in s, to one decimal place; report its second numeric field as a voltage in V, to one decimal place; and give the exact integer number of data records written. Exclude the header when numbering and counting data records.