0
0
MATLABdata~20 mins

Excel file reading and writing in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Excel File Mastery in MATLAB
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this MATLAB code reading an Excel file?
Consider the following MATLAB code that reads data from an Excel file named 'data.xlsx'. What will be the value of variable data after running this code?
MATLAB
data = readtable('data.xlsx');
disp(data(1, :));
ADisplays the first row of the Excel file as a table with column headers
BThrows an error because 'readtable' cannot read Excel files
CDisplays the entire Excel file content as a numeric matrix
DDisplays only the first cell value of the Excel file
Attempts:
2 left
💡 Hint
The function readtable reads Excel files into a table with headers.
Predict Output
intermediate
2:00remaining
What does this MATLAB code write to an Excel file?
Given the MATLAB code below, what will be the content of the Excel file 'output.xlsx' after execution?
MATLAB
T = table([1;2;3], {'A';'B';'C'}, 'VariableNames', {'Numbers', 'Letters'});
writecell({'Header1', 'Header2'; 10, 20}, 'output.xlsx');
writetable(T, 'output.xlsx', 'Sheet', 1, 'WriteMode', 'append');
AThe Excel file will have one sheet with the cell array overwritten by the table
BThe Excel file will have one sheet with the cell array in the first two rows and the table appended below
CThe code will cause an error because 'WriteMode' is not a valid option
DThe Excel file will have two sheets: first with the cell array and second with the table
Attempts:
2 left
💡 Hint
The 'WriteMode' option 'append' adds data below existing content in the same sheet.
🔧 Debug
advanced
2:00remaining
Why does this MATLAB code fail to read the Excel file?
This MATLAB code attempts to read an Excel file but throws an error. What is the cause?
MATLAB
data = xlsread('missingfile.xlsx');
AThe file 'missingfile.xlsx' does not exist in the current folder or path
BThe file is open in another program, causing a permission error
CThe code is missing a sheet name argument
DThe function 'xlsread' is deprecated and cannot read Excel files
Attempts:
2 left
💡 Hint
Check if the file exists in the folder where MATLAB is running.
📝 Syntax
advanced
2:00remaining
Which option correctly writes a MATLAB table to an Excel file with a custom sheet name?
Select the MATLAB code snippet that correctly writes the table T to an Excel file named 'results.xlsx' on a sheet called 'Summary'.
MATLAB
T = table([10;20], {'X';'Y'}, 'VariableNames', {'Value', 'Category'});
Awritetable('results.xlsx', T, 'Sheet', 'Summary');
Bwritetable(T, 'results.xlsx', 'SheetName', 'Summary');
Cwritetable(T, 'results.xlsx', 'Sheet', 'Summary');
Dwritetable(T, 'results.xlsx', 'Sheet', 1, 'SheetName', 'Summary');
Attempts:
2 left
💡 Hint
The correct option uses the 'Sheet' name-value pair to specify the sheet.
🚀 Application
expert
3:00remaining
How many rows will the variable data contain after this code runs?
This MATLAB code reads data from an Excel file 'sales.xlsx' that has 100 rows and 5 columns. The code filters rows where the 'Amount' column is greater than 500. How many rows will data contain?
MATLAB
T = readtable('sales.xlsx');
data = T(T.Amount > 500, :);
A5 rows, equal to the number of columns in the file
B0 rows, because the condition is invalid
C100 rows, same as the original file
DThe number of rows in <code>data</code> equals the count of rows in 'sales.xlsx' where 'Amount' > 500
Attempts:
2 left
💡 Hint
The code filters rows based on the 'Amount' column values.