MATLAB Interview Questions
Short model answers; each points to the module with a verified example.
Concept
Short model answers; each points to the module with a verified example.
What is MATLAB?
A matrix-based language and environment for numerical computing, visualization and model-based design (Module 1) Script vs function?
Scripts share the base workspace; functions have their own workspace and inputs/outputs (Module 11) Default data type?
double (Module 2) What does the semicolon do?
Suppresses display of the result Matrix multiplication vs element-wise multiplication (Module 3)
Element-wise vs short-circuit scalar logical AND Is MATLAB 0- or 1-indexed?
1-indexed; end is the last index (Module 5) What is column-major order?
Arrays are stored column by column; affects linear indexing and reshape (Module 4) How do you solve A x = b?
x = A \ b, not inv(A) * b (Module 6) Cell array vs struct vs matrix?
Heterogeneous containers indexed by position / named fields / homogeneous numeric grid (Modules 14–15) What is vectorization?
Operating on whole arrays instead of element loops — shorter, usually faster (Module 13) Why preallocate?
Growing arrays forces repeated reallocation and copying (Module 13, 29) What is logical indexing?
Selecting elements with a true/false mask: v(v > 0) What is a function handle?
A value referring to a function, used to pass functions to solvers (Module 12) What do anonymous functions capture?
The values of variables at creation time Number of inputs passed / outputs requested How do you handle errors?
try/catch with MException, identifiers, rethrow, onCleanup (Module 20) How do you read a CSV?
readmatrix/readtable (MATLAB), csvread, textscan (Module 17) containers.Map vs struct?
Map: arbitrary keys, dynamic; struct: fixed, named fields (Module 16) Value vs handle class?
Copy semantics vs reference semantics (Module 28) Advanced / Engineering ode45 vs ode15s?
Non-stiff explicit RK45 vs stiff implicit solver (Module 23) How do you fit a model to data?
polyfit for polynomials, A \ y for linear least squares, fminsearch/lsqcurvefit for nonlinear (Modules 21, 24) What is the condition number?
Sensitivity of a linear system's solution to data errors (Module 22) How do you compute a spectrum?
fft, scale by N, double the single-sided part, f = k·fs/N (Module 25) What is aliasing?
Frequencies above fs/2 folding back to lower frequencies Finite vs infinite impulse response: stability/linear phase vs efficiency (Module 25) What does each PID term do?
P: present error, I: removes steady-state error, D: damping (Module 26) How do you speed up MATLAB code?
Profile, vectorize, preallocate, built-ins, \, parfor, MEX/Coder (Module 29) What is Simulink / model-based design?
Graphical dynamic modelling with simulation and code generation for embedded targets (Module 31) How would you decode a CAN signal?
Extract bytes, combine with the right byte order (bitshift), apply factor and offset (Module 30)
Why It Matters
MATLAB appears in interviews for controls, signal processing, automotive, aerospace, data analysis and research roles — usually as practical questions about vectorization, indexing and numerical methods.
Syntax
Answer pattern: definition → MATLAB syntax → example → pitfall.
Example
Every answer above has a runnable, verified example in the referenced module. Practising with those scripts lets you answer with what you *observed*.
Expected Result
You should be able to answer each question in two or three sentences and write the corresponding one-line MATLAB expression.
Common Mistakes
Answering with loops when the interviewer expects vectorized code.
Mixing up */.* or &/&& under pressure.
Not mentioning numerical pitfalls (conditioning, tolerances, stiffness).
Best Practices
Practise writing code on paper for indexing and vectorization problems.
Know the complexity/performance implications of your answers.
Prepare a story about a real analysis or model you built.
Practice Questions
Explain the difference between A' and A.'.
Write a one-liner that returns the indices of the three largest values of a vector.
Explain why ode45 is slow for stiff systems.
Describe how you would validate a Simulink model against test data.
Quick Quiz
Q1. (Multiple choice) Which is the idiomatic way to square every element of v? A) v^2 B) v.^2 C) v*v D) power(v) Answer: B.
Q2. (True/False) A \ b and inv(A) * b always give identical results.
Answer: False. They agree for well-conditioned systems up to rounding, but \ is more accurate and faster.
Q3. (Predict the output) numel(magic(4)) Answer: 16.
Q4. (Find the bug) "I vectorized my loop with arrayfun, so it must be fast now."
Answer: arrayfun hides the loop but doesn't necessarily speed it up; true vectorization uses array operations.
Coding Challenge
Return the indices of the three largest values of v = [4 9 1 7 3 9 2] (ties in original order) in one statement, then print them.
v = [4 9 1 7 3 9 2];
[~, order] = sort(v, 'descend');
top3 = order(1:3);
fprintf('indices of the three largest values: %s (values %s)\n', mat2str(top3), mat2str(v(top3)))