0
0
MATLABdata~10 mins

Reading text files (readtable, textscan) in MATLAB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read a table from 'data.csv' using readtable.

MATLAB
T = [1]('data.csv');
Drag options to blanks, or click blank then click option'
Areadtable
Btextscan
Cfopen
Dload
Attempts:
3 left
💡 Hint
Common Mistakes
Using fopen instead of readtable
Using load which is for MAT-files
2fill in blank
medium

Complete the code to open a text file named 'file.txt' for reading.

MATLAB
fid = [1]('file.txt', 'r');
Drag options to blanks, or click blank then click option'
Areadtable
Bfopen
Ctextscan
Dfclose
Attempts:
3 left
💡 Hint
Common Mistakes
Using readtable which reads tables, not opening files
Using fclose which closes files
3fill in blank
hard

Fix the error in the code to read numeric data from a file using textscan.

MATLAB
fid = fopen('numbers.txt', 'r');
data = [1](fid, '%f');
fclose(fid);
Drag options to blanks, or click blank then click option'
Atextscan
Bfopen
Creadtable
Dfclose
Attempts:
3 left
💡 Hint
Common Mistakes
Using fopen instead of textscan to read data
Using readtable which reads tables, not formatted data
4fill in blank
hard

Fill both blanks to read a CSV file with headers and convert it to a table.

MATLAB
opts = detectImportOptions('data.csv');
opts.[1] = 1;
T = [2]('data.csv', opts);
Drag options to blanks, or click blank then click option'
AVariableNamesLine
Breadtable
CDelimiter
Dtextscan
Attempts:
3 left
💡 Hint
Common Mistakes
Using textscan instead of readtable for tables
Setting Delimiter instead of VariableNamesLine
5fill in blank
hard

Fill all three blanks to read a file line by line using textscan and close it.

MATLAB
fid = [1]('log.txt', 'r');
data = [2](fid, '%s', 'Delimiter', '\n');
[3](fid);
Drag options to blanks, or click blank then click option'
Afopen
Btextscan
Cfclose
Dreadtable
Attempts:
3 left
💡 Hint
Common Mistakes
Using readtable instead of fopen or fclose
Not closing the file after reading