0
0
MATLABdata~10 mins

File path handling 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 join folder and file name into a full path.

MATLAB
fullPath = fullfile([1], 'data.txt');
Drag options to blanks, or click blank then click option'
AfolderName
BfileName
CpathName
DfilePath
Attempts:
3 left
💡 Hint
Common Mistakes
Using the file name variable instead of the folder name.
Using a variable that does not exist.
2fill in blank
medium

Complete the code to extract the file extension from a file path.

MATLAB
[~, ~, [1]] = fileparts(filePath);
Drag options to blanks, or click blank then click option'
Aextension
Bfolder
Cfilename
Dfilepath
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong output position for the extension.
Confusing file name with extension.
3fill in blank
hard

Fix the error in the code to check if a path is a folder.

MATLAB
if isfolder([1])
    disp('It is a folder.');
end
Drag options to blanks, or click blank then click option'
AfilePath
BfolderPath
CfileName
DfileExtension
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a file name or extension instead of a folder path.
Using a variable that does not represent a folder.
4fill in blank
hard

Fill both blanks to create a path and check if it exists.

MATLAB
fullPath = fullfile([1], [2]);
if exist(fullPath, 'file')
    disp('File exists.');
end
Drag options to blanks, or click blank then click option'
AfolderName
BfileName
CfolderPath
DfileExtension
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping folder and file name in fullfile.
Using file extension instead of file name.
5fill in blank
hard

Fill all three blanks to split a path and rebuild it with a new extension.

MATLAB
[folder, name, [1]] = fileparts(oldPath);
newPath = fullfile(folder, [name [2] [3]]);
Drag options to blanks, or click blank then click option'
Aextension
B'.'
C'txt'
D'/'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names for extension.
Using slash '/' instead of dot '.' for extension separator.