Challenge - 5 Problems
Excel File Mastery in MATLAB
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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, :));
Attempts:
2 left
💡 Hint
The function
readtable reads Excel files into a table with headers.✗ Incorrect
The
readtable function reads the Excel file into a table preserving headers. Displaying data(1, :) shows the first row with all columns as a table.❓ Predict Output
intermediate2: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');
Attempts:
2 left
💡 Hint
The 'WriteMode' option 'append' adds data below existing content in the same sheet.
✗ Incorrect
First,
writecell writes a 2x2 cell array to 'output.xlsx'. Then writetable appends the table below the existing data in the same sheet because of 'WriteMode', so both appear in one sheet.🔧 Debug
advanced2: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');Attempts:
2 left
💡 Hint
Check if the file exists in the folder where MATLAB is running.
✗ Incorrect
The error occurs because the file 'missingfile.xlsx' is not found in the current folder or MATLAB path. The function
xlsread requires the file to exist and be accessible.📝 Syntax
advanced2: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'});
Attempts:
2 left
💡 Hint
The correct option uses the 'Sheet' name-value pair to specify the sheet.
✗ Incorrect
The
writetable function uses the 'Sheet' parameter to specify the sheet name. Option C correctly uses 'Sheet', 'Summary'. Option C uses a non-existent parameter 'SheetName'. Option C has wrong argument order. Option C mixes numeric and name parameters incorrectly.🚀 Application
expert3: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, :);
Attempts:
2 left
💡 Hint
The code filters rows based on the 'Amount' column values.
✗ Incorrect
The code reads the entire table, then selects only rows where the 'Amount' column value is greater than 500. The number of rows in
data depends on how many rows satisfy this condition in the Excel file.