Bird
0
0

What is the output of the following MATLAB code?

medium📝 Predict Output Q13 of 15
MATLAB - File I/O
What is the output of the following MATLAB code?
fullPath = fullfile('C:', 'Users', 'Documents', 'file.txt');
[folder, name, ext] = fileparts(fullPath);
disp(folder)
Afile.txt
BC:\Users\Documents
CC:/Users/Documents/file.txt
DDocuments
Step-by-Step Solution
Solution:
  1. Step 1: Understand fullfile output

    fullfile joins parts into a full path: 'C:\Users\Documents\file.txt' (Windows style).
  2. Step 2: Use fileparts to split the path

    fileparts splits into folder = 'C:\Users\Documents', name = 'file', ext = '.txt'.
  3. Final Answer:

    C:\Users\Documents -> Option B
  4. Quick Check:

    fileparts folder output = C:\Users\Documents [OK]
Quick Trick: fileparts(folder) excludes file name and extension [OK]
Common Mistakes:
  • Expecting file name or extension as folder output
  • Confusing path separators (\ vs /)
  • Thinking fullfile returns a list instead of string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes