MATLAB Data Import and Visualization 3 — Questions and Answers
Question 1: Which MATLAB function reads data from a specific sheet of an Excel workbook?
- readmatrix('file.xlsx','Sheet','Sheet2') (Correct answer)
- xlsopen('file.xlsx',2)
- loadsheet('file.xlsx',2)
- importsheet('file.xlsx','Sheet2')
Correct answer: readmatrix('file.xlsx','Sheet','Sheet2')
readmatrix (and readtable/readcell) accept the 'Sheet' name-value pair to specify which worksheet to read from a multi-sheet Excel file.
Question 2: What is the primary difference between 'plot' and 'scatter' in MATLAB?
- scatter allows per-point color and size control while plot uses uniform line style (Correct answer)
- scatter connects points with lines while plot does not
- plot supports 3D while scatter is 2D only
- scatter automatically fits a regression line
Correct answer: scatter allows per-point color and size control while plot uses uniform line style
scatter lets you specify individual marker sizes and colors as vectors, making it ideal for visualizing a third or fourth variable through marker attributes.
Question 3: Which function saves a MATLAB figure to a PNG file?
- exportgraphics(fig,'out.png')
- saveas(fig,'out','png')
- print('-dpng','out.png')
- All of the above are valid (Correct answer)
Correct answer: All of the above are valid
All three methods—exportgraphics, saveas, and print—can export a MATLAB figure to PNG, though exportgraphics (R2020a+) offers the most control over resolution and tight bounding boxes.
Question 4: What does 'tiledlayout(2,3)' do in MATLAB?
- Creates a 2-row by 3-column grid of axes tiles in the current figure (Correct answer)
- Creates 2 figures each with 3 subplots
- Divides the x-axis into 2 and y-axis into 3 equal parts
- Sets the figure tile to display 2 rows of 3 images
Correct answer: Creates a 2-row by 3-column grid of axes tiles in the current figure
tiledlayout (R2019b+) creates a layout manager for arranging multiple axes in a figure; 'nexttile' then places each axes in the next available cell.
Question 5: When using 'fread' to read binary data, what does the 'precision' argument control?
- The data type of each value read from the file (Correct answer)
- The number of decimal places retained
- The file seek position after reading
- The byte order (endianness) of the file
Correct answer: The data type of each value read from the file
The precision argument in fread specifies the data type (e.g., 'int16', 'float32', 'uint8') of each element to be read from the binary file.
Question 6: What MATLAB function retrieves the names of variables stored in a .mat file without loading them into memory?
- whos('-file','data.mat') (Correct answer)
- load('-info','data.mat')
- matinfo('data.mat')
- varnames('data.mat')
Correct answer: whos('-file','data.mat')
whos('-file','filename') returns information about variables in a MAT-file including their names, sizes, and types without loading the data.
Question 7: Which MATLAB function creates a filled contour plot?
- contourf (Correct answer)
- contour
- meshc
- pcolor
Correct answer: contourf
contourf creates a filled contour plot where the regions between contour lines are filled with color, unlike contour which draws only the lines.
Which MATLAB function reads data from a specific sheet of an Excel workbook?