Bird
0
0

Given the following MATLAB code snippet, what will be the output stored in data?

medium📝 Predict Output Q13 of 15
MATLAB - File I/O
Given the following MATLAB code snippet, what will be the output stored in data?
fileID = fopen('numbers.txt', 'r');
data = textscan(fileID, '%d %f');
fclose(fileID);
Assuming numbers.txt contains:
10 3.14
20 2.71
30 1.62
AA 1x2 cell array with first cell [10;20;30] and second cell [3.14;2.71;1.62]
BA 3x2 numeric matrix with all numbers
CA single numeric array combining all values
DAn error because textscan cannot read mixed data
Step-by-Step Solution
Solution:
  1. Step 1: Understand textscan output format

    textscan returns a cell array where each cell contains a column of data matching the format specifiers.
  2. Step 2: Analyze the format and file content

    Format '%d %f' reads an integer and a float per line. The file has 3 lines, so the first cell will be [10;20;30] and the second cell [3.14;2.71;1.62].
  3. Final Answer:

    A 1x2 cell array with first cell [10;20;30] and second cell [3.14;2.71;1.62] -> Option A
  4. Quick Check:

    textscan returns cell array columns [OK]
Quick Trick: textscan returns cells, each for one format column [OK]
Common Mistakes:
  • Expecting a numeric matrix instead of cell array
  • Thinking textscan merges all data into one array
  • Assuming textscan cannot read mixed types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes