Challenge - 5 Problems
CSV Mastery in MATLAB
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Reading CSV with readmatrix
What is the output of this MATLAB code when reading a CSV file with numeric data only?
MATLAB
data = readmatrix('data.csv');
disp(data);Attempts:
2 left
💡 Hint
readmatrix reads numeric data into a numeric array.
✗ Incorrect
readmatrix reads numeric CSV data into a numeric matrix. If the file contains only numbers, the output is a numeric array.
❓ Predict Output
intermediate2:00remaining
Writing CSV with writematrix
What will be the content of 'output.csv' after running this MATLAB code?
MATLAB
M = [10 20 30; 40 50 60]; writematrix(M, 'output.csv');
Attempts:
2 left
💡 Hint
writematrix writes numeric arrays as CSV rows.
✗ Incorrect
writematrix writes each row of the matrix as a line in the CSV file, with commas separating values.
🔧 Debug
advanced2:00remaining
Reading mixed data CSV with readmatrix
What is the result of this MATLAB code when reading a CSV file with mixed text and numbers using readmatrix?
MATLAB
data = readmatrix('mixed.csv');Attempts:
2 left
💡 Hint
readmatrix converts non-numeric data to NaN.
✗ Incorrect
readmatrix reads the file into a numeric matrix, replacing text or non-numeric data with NaN. No error occurs.
❓ Predict Output
advanced2:00remaining
Reading CSV with readtable and accessing data
Given a CSV file 'people.csv' with columns 'Name,Age,Height', what is the output of this code?
MATLAB
T = readtable('people.csv'); disp(T.Age(2));
Attempts:
2 left
💡 Hint
readtable creates a table with column names as fields.
✗ Incorrect
readtable reads CSV into a table. Accessing T.Age(2) returns the second row's Age value.
🧠 Conceptual
expert2:00remaining
Choosing the best function for mixed CSV data
Which MATLAB function is best suited to read a CSV file containing both numeric and text data with headers?
Attempts:
2 left
💡 Hint
Consider which function handles mixed data and headers well.
✗ Incorrect
readtable reads CSV files with mixed data types and headers into a table, preserving data types and column names.