Exam
**Question 1.** Which MATLAB data type is most appropriate for storing heterogeneous data
such as strings, numbers, and arrays of different sizes?
A) double
B) cell array
C) struct
D) table
**Answer:** B
**Explanation:** Cell arrays can hold elements of different types and sizes, making them ideal
for heterogeneous collections.
**Question 2.** What is the result of the MATLAB command `size([1 2 3; 4 5 6])`?
A) 2‑by‑3
B) 3‑by‑2
C) 1‑by‑6
D) 6‑by‑1
**Answer:** A
**Explanation:** The matrix has 2 rows and 3 columns, so `size` returns `[2 3]`.
**Question 3.** Which of the following statements about the `for` loop in MATLAB is FALSE?
A) The loop index variable can be modified inside the loop body.
B) The loop iterates over a vector of values.
C) Pre‑allocating the loop variable improves performance.
D) Nested `for` loops are allowed.
**Answer:** C
**Explanation:** Pre‑allocating the loop index variable does not affect performance;
pre‑allocating arrays used inside the loop does.
, Certified MATLAB Professional Practice
Exam
**Question 4.** Which vectorized function can replace the loop `for i=1:n; y(i)=sin(x(i)); end`?
A) `y = sin(x);`
B) `y = arrayfun(@sin,x);`
C) `y = sum(sin(x));`
D) `y = cumprod(sin(x));`
**Answer:** A
**Explanation:** MATLAB’s built‑in `sin` operates element‑wise on arrays, eliminating the need
for an explicit loop.
**Question 5.** In a MATLAB function, which keyword allows an undefined number of input
arguments?
A) `varargin`
B) `varargout`
C) `nargin`
D) `nargout`
**Answer:** A
**Explanation:** `varargin` collects excess inputs into a cell array, enabling variable‑length
argument lists.
**Question 6.** Which of the following correctly defines an anonymous function that computes
the square of its input?
A) `f = @(x) x.^2;`
B) `f = @(x) x*2;`
C) `f = @(x) pow(x,2);`
D) `f = @(x) square(x);`
, Certified MATLAB Professional Practice
Exam
**Answer:** A
**Explanation:** The anonymous function uses element‑wise power (`.^`) to square the input.
**Question 7.** What does the MATLAB command `nargout(@plot)` return?
A) Number of input arguments that `plot` accepts.
B) Number of output arguments that `plot` can return.
C) Number of lines in the `plot` source file.
D) Number of graphics objects created by `plot`.
**Answer:** B
**Explanation:** `nargout` reports how many outputs a function can produce; `plot` can return
a graphics handle.
**Question 8.** Which of the following is the most efficient way to grow a large numeric array
inside a loop?
A) Append using `A = [A; newRow];` each iteration.
B) Pre‑allocate with `A = zeros(N,M);` before the loop.
C) Use `A(end+1,:) = newRow;` each iteration.
D) Create a cell array and convert later.
**Answer:** B
**Explanation:** Pre‑allocation avoids repeated memory reallocation, dramatically improving
performance.
**Question 9.** Which MATLAB construct is used to create a class property that cannot be
modified after object construction?
A) `SetAccess = private`
B) `GetAccess = public`
, Certified MATLAB Professional Practice
Exam
C) `Constant`
D) `Dependent`
**Answer:** C
**Explanation:** `Constant` properties are fixed at compile time and cannot be changed after
the object is created.
**Question 10.** In MATLAB OOP, which keyword is used to inherit properties and methods
from a superclass?
A) `extends`
B) `inherits`
C) `subclass`
D) `<` (angle bracket)
**Answer:** D
**Explanation:** Class definitions use the syntax `classdef SubClass < SuperClass` to indicate
inheritance.
**Question 11.** Which command creates a breakpoint that only triggers when variable `k`
exceeds 10?
A) `dbstop if k>10`
B) `dbstop if error`
C) `dbstop if warning`
D) `dbstop if expression k>10`
**Answer:** D
**Explanation:** `dbstop if expression <expr>` sets a conditional breakpoint based on a logical
expression.