A. The 'Sheet' parameter must be a string, not a number
B. The 'Range' parameter cannot be used with writetable
C. The filename must include full path
D. writetable cannot write to Excel files
Solution
Step 1: Check the 'Sheet' parameter type
In writetable, the 'Sheet' argument should be a string with sheet name, not a numeric index.
Step 2: Validate other parameters
'Range' is valid, filename can be relative, and writetable supports Excel files.
Final Answer:
The 'Sheet' parameter must be a string, not a number -> Option A
Quick Check:
Sheet name must be string in writetable [OK]
Hint: Use sheet names as strings, not numbers, in writetable [OK]
Common Mistakes:
Passing sheet number instead of name
Thinking Range is invalid for writetable
Assuming filename needs full path always
5. You want to read only the numeric data from the range B2:D10 in sheet Data of metrics.xlsx into MATLAB as a table. Which code snippet correctly does this and then writes only the first 5 rows back to a new Excel file subset.xlsx?
hard
A. T = readmatrix('metrics.xlsx', 'Sheet', 'Data', 'Range', 'B2:D10');
writetable(T(1:5,:), 'subset.xlsx');
B. T = readtable('metrics.xlsx', 'Sheet', 'Data', 'Range', 'B2:D10');
writetable(T(1:5,:), 'subset.xlsx');
C. T = readtable('metrics.xlsx', 'Sheet', 'Data', 'Range', 'B2:D10');
writetable(T(1:5));
D. T = readmatrix('metrics.xlsx', 'Sheet', 'Data', 'Range', 'B2:D10');
writetable(T, 'subset.xlsx');
Solution
Step 1: Read numeric data as a table
Use readtable with 'Sheet' and 'Range' to get data as a table.
Step 2: Write first 5 rows to new Excel file
Use writetable with T(1:5,:) to write first 5 rows correctly.
Final Answer:
T = readtable('metrics.xlsx', 'Sheet', 'Data', 'Range', 'B2:D10');
writetable(T(1:5,:), 'subset.xlsx'); -> Option B