Bird
0
0

If people.txt contains:

medium📝 Predict Output Q5 of 15
MATLAB - File I/O
If people.txt contains:
Sarah 28
Tom 35
Linda 40

What will be the content of ages after running:
fid = fopen('people.txt', 'r');
C = textscan(fid, '%s %d');
fclose(fid);
names = C{1};
ages = C{2};
A['28', '35', '40']
B[28; 35; 40]
C["Sarah", "Tom", "Linda"]
D[28 35 40 0]
Step-by-Step Solution
Solution:
  1. Step 1: Use textscan with '%s %d'

    This reads a string and an integer per line.
  2. Step 2: Extract ages

    C{2} contains the integer column as a numeric column vector.
  3. Final Answer:

    [28; 35; 40] -> Option B
  4. Quick Check:

    Numeric data is stored as numeric array, not strings [OK]
Quick Trick: Numeric columns become numeric arrays, not strings [OK]
Common Mistakes:
  • Assuming numeric data is stored as strings
  • Confusing cell array content with numeric arrays
  • Expecting extra zeros or padding

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes