MATLAB Data Import and Visualization 5 — Questions and Answers
Question 1: Which MATLAB function reads a JSON file and converts it to a MATLAB structure?
- jsondecode(fileread('data.json')) (Correct answer)
- jsonload('data.json')
- readjson('data.json')
- importjson('data.json')
Correct answer: jsondecode(fileread('data.json'))
MATLAB has no single jsonread function; the standard pattern is fileread() to get the raw text then jsondecode() to parse it into a struct.
Question 2: What does 'subplot(2,2,3)' specify in MATLAB?
- The axes in the bottom-left position of a 2x2 grid (Correct answer)
- The third figure in a set of 4 figures
- An axes spanning rows 2-3 in a 2-column layout
- The axes at row 2, column 2
Correct answer: The axes in the bottom-left position of a 2x2 grid
subplot(m,n,p) selects axes number p in an m-by-n grid; positions are numbered left-to-right, top-to-bottom, so position 3 is bottom-left in a 2x2 grid.
Question 3: What is the purpose of 'detectImportOptions' in MATLAB?
- Automatically detects and returns configurable import options for a file (Correct answer)
- Checks if a file can be imported without errors
- Selects the fastest import function for a given file type
- Detects encoding and byte-order of binary files
Correct answer: Automatically detects and returns configurable import options for a file
detectImportOptions inspects a file and returns an ImportOptions object pre-configured for that file, which you can then modify before passing to readtable or readmatrix.
Question 4: Which property of a MATLAB line object controls the thickness of the plotted line?
- LineWidth (Correct answer)
- LineThickness
- Width
- StrokeWidth
Correct answer: LineWidth
The LineWidth property (in points) controls the rendered thickness of line and marker edge strokes on a MATLAB plot object.
Question 5: What does 'yyaxis right' do in MATLAB?
- Activates the right y-axis so subsequent plot commands use it (Correct answer)
- Moves the current y-axis label to the right side
- Creates a second figure with axes on the right
- Flips the y-axis direction to increase rightward
Correct answer: Activates the right y-axis so subsequent plot commands use it
yyaxis right switches the active y-axis to the right side; subsequent plot commands will be associated with the right y-axis scale.
Question 6: When would you use 'readlines' instead of 'readtable' in MATLAB?
- When reading a plain text file as an array of string lines without parsing structure (Correct answer)
- When reading very large tables for better performance
- When importing multi-line cell entries from Excel
- When reading binary line-terminated data
Correct answer: When reading a plain text file as an array of string lines without parsing structure
readlines reads a text file and returns each line as a string in a string array, useful for unstructured text, logs, or files you intend to parse manually.
Question 7: Which MATLAB function converts a datetime array to a numeric format suitable for plot axis ticks?
- datenum (Correct answer)
- datestr
- datevec
- caldays
Correct answer: datenum
datenum converts a datetime or date string to a serial date number (days since Jan 0, 0000), which MATLAB's older plotting functions use for date-based axes.
Which MATLAB function reads a JSON file and converts it to a MATLAB structure?