Bird
0
0

Consider this MATLAB code snippet:

medium📝 Debug Q14 of 15
MATLAB - File I/O
Consider this MATLAB code snippet:
T = readtable('data.csv');
writetable(T, 'output.csv');

If data.csv contains mixed numeric and text data, what is a common error to watch for?
AUsing <code>csvwrite</code> to write tables causes incorrect output
BUsing <code>writetable</code> on a numeric matrix causes syntax error
CForgetting to close the file after reading causes runtime error
DUsing <code>readmatrix</code> instead of <code>readtable</code> causes syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand data type in CSV

    Mixed numeric and text data require table format to preserve all data correctly.
  2. Step 2: Identify correct write function

    csvwrite only supports numeric data and will fail or produce incorrect output for tables.
  3. Final Answer:

    Using csvwrite to write tables causes incorrect output -> Option A
  4. Quick Check:

    csvwrite not for tables = error [OK]
Quick Trick: Use writetable for mixed data, not csvwrite [OK]
Common Mistakes:
  • Using readmatrix for mixed data losing text
  • Assuming file must be closed manually in MATLAB
  • Using writetable on numeric matrix without conversion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes