
















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A technical exam covering MATLAB syntax, matrix operations, script development, data visualization, function creation, algorithm development, Simulink basics, and applied mathematics. Includes engineering and scientific scenarios requiring simulation, numerical modeling, and data analysis tasks.
Typology: Exams
1 / 88
This page cannot be seen from the preview
Don't miss anything!

















































































Question 1. Which MATLAB window displays the list of variables currently in memory? A) Command Window B) Workspace C) Current Folder D) Editor Answer: B Explanation: The Workspace window shows all variables that have been created during the session. Question 2. What does the command clc do? A) Clears all variables B) Clears the command window screen C) Clears the workspace history D) Clears all figures Answer: B Explanation: clc clears the text in the Command Window but does not affect variables or figures. Question 3. Which operator performs element‑wise multiplication of two matrices A and B? A) * B) .* C) .^ D) \ Answer: B Explanation: .* multiplies corresponding elements; * performs matrix multiplication. Question 4. What is the result of sqrt(-4) in MATLAB?
A) 2i B) -2 C) NaN D) 4 Answer: A Explanation: MATLAB returns a complex result for the square root of a negative number; sqrt(-4) = 2i. Question 5. Which function creates a 3‑by‑4 matrix of ones? A) zeros(3,4) B) ones(3,4) C) eye(3,4) D) rand(3,4) Answer: B Explanation: ones(m,n) generates an m‑by‑n matrix filled with 1. Question 6. How would you generate a row vector containing the integers from 5 to 15 with a step of 2? A) 5:2:15 B) linspace(5,15,2) C) 5:15:2 D) colon(5,2,15) Answer: A Explanation: The colon syntax start:step:end creates the required vector. Question 7. Which command returns the number of elements in a matrix M?
A) help fft B) doc fft C) info fft D) type fft Answer: B Explanation: doc opens the full HTML documentation; help shows a text summary. Question 11. What is the output type of the expression ['MAT' 'LAB']? A) Cell array of strings B) Character array (1‑by‑6) C) String scalar D) Numeric array Answer: B Explanation: Concatenating character vectors with [] produces a single character array. Question 12. Which function converts a character array c to a string scalar? A) string(c) B) char(c) C) toString(c) D) cellstr(c) Answer: A Explanation: string creates a string object from character or numeric data. Question 13. How do you access the third element of a cell array C? A) C{3}
C(3)C[3]C(3,:)Answer: A Explanation: Curly braces {} extract the contents of a cell; parentheses return a sub‑cell. Question 14. Given the structure S.name = 'Alice'; S.age = 30;, how would you retrieve the age? A) S(2) B) S{'age'} C) S.age D) S[2] Answer: C Explanation: Dot notation accesses fields of a structure. Question 15. Which function reads a CSV file named data.csv into a table? A) readtable('data.csv') B) csvread('data.csv') C) importdata('data.csv') D) load('data.csv') Answer: A Explanation: readtable automatically creates a table with variable names from the header row. Question 16. What does the command datetime('now','TimeZone','local') return? A) Current date as a string B) Current date and time as a datetime object
D) accumarray(v) Answer: A Explanation: cumsum computes the running total of the elements. Question 20. Which function creates a 2‑D line plot of x versus y? A) plot(x,y) B) line(x,y) C) graph(x,y) D) scatter(x,y) Answer: A Explanation: plot is the standard function for line plots. Question 21. To add a legend labeling the first plotted data series as “Signal”, which command is used? A) legend('Signal') B) title('Signal') C) label('Signal') D) xlabel('Signal') Answer: A Explanation: legend creates a legend box with the supplied string(s). Question 22. Which line of code holds the current figure so that subsequent plot commands add to it? A) hold on B) hold all C) freeze on
D) keep on Answer: A Explanation: hold on retains existing plots while adding new graphics. Question 23. How do you create a 2‑by‑2 grid of subplots and activate the third subplot? A) subplot(2,2,3) B) subplot(3,2,2) C) subfigure(2,2,3) D) axes(3) Answer: A Explanation: subplot(m,n,p) creates an m‑by‑n grid and activates the p‑th subplot. Question 24. Which function produces a 3‑D surface plot from matrix Z? A) surf(Z) B) mesh(Z) C) contour(Z) D) plot3(Z) Answer: A Explanation: surf renders a colored surface defined by the height matrix Z. Question 25. Which command saves the variable A to a MAT‑file called mydata.mat? A) save('mydata.mat','A') B) write('mydata.mat',A) C) export('mydata.mat',A) D) store('mydata.mat','A')
D) Pause execution for debugging Answer: B Explanation: break exits the nearest enclosing for or while loop. Question 29. Which construct correctly defines a function that returns the square of its input x? A) function y = square(x); y = x.^2; end B) function y = square; y = x.^2; end C) function square(x); y = x.^2; end D) function [y] = square(x) y = x^2 end Answer: A Explanation: The syntax includes the output variable, input argument, and the body; the semicolon after the header is optional. Question 30. How would you create an anonymous function that computes the cube of a number z? A) cube = @(z) z.^3; B) cube(z) = z.^3; C) cube = function(z) z.^3; D) cube = @(z) z^3; Answer: A Explanation: Anonymous functions use the @ operator; element‑wise power .^ is appropriate for vectorized input. Question 31. Which command sets the numeric display format to show 4 decimal places? A) format short B) format long
C) format bank D) format compact Answer: A Explanation: format short displays four digits after the decimal for floating‑point numbers. Question 32. What does the command clearvars - except A B do? A) Clears all variables except A and B B) Clears only A and B C) Clears the workspace and keeps A and B in memory D) Clears the command history except for A and B Answer: A Explanation: clearvars - except removes all workspace variables except the listed ones. Question 33. Which function can be used to find the indices of all elements in vector v that are equal to 0? A) find(v==0) B) where(v,0) C) index(v,0) D) locate(v,0) Answer: A Explanation: find returns linear indices where the logical condition is true. Question 34. In MATLAB, which operator concatenates two matrices horizontally? A) ; B) ,
C) clc D) hide Answer: B Explanation: Adding a semicolon at the end of a statement suppresses its output. Question 38. Which command returns the size of matrix M as a two‑element row vector? A) size(M) B) length(M) C) numel(M) D) dim(M) Answer: A Explanation: size returns [rows columns]; length returns the longest dimension. Question 39. What is the result of mod(-7,3)? A) -1 B) 2 C) -2 D) 1 Answer: B Explanation: mod returns the remainder after division, always non‑negative when the divisor is positive; -7 = - 3*3 + 2. Question 40. Which function converts a numeric array N to a cell array where each element is a separate cell? A) num2cell(N) B) cell(N)
C) mat2cell(N) D) cell2mat(N) Answer: A Explanation: num2cell places each element of N into its own cell. Question 41. To access the field height of every element in a structure array S, which syntax is correct? A) [S.height] B) S{height} C) S.height(:) D) S(:).height Answer: A Explanation: Bracket notation concatenates the values of the specified field from each structure. Question 42. Which command creates a logical mask that is true for rows of matrix A where the sum of the row exceeds 10? A) mask = sum(A,2) > 10; B) mask = rowSum(A) > 10; C) mask = sum(A) > 10; D) mask = any(A,2) > 10; Answer: A Explanation: sum(A,2) computes row sums; the relational operation creates the logical mask. Question 43. Which function can be used to read a specific sheet named “Results” from an Excel file report.xlsx into a table? A) readtable('report.xlsx','Sheet','Results')
B) unique(v) C) distinct(v) D) set(v) Answer: A Explanation: The 'stable' option preserves the original order. Question 47. What does the command tic; pause(2); toc display? A) Approximately 2 seconds B) The current time stamp C) The CPU time used by MATLAB D) Nothing, because tic and toc are mismatched Answer: A Explanation: tic starts a timer; toc reports elapsed time since the last tic. Question 48. Which of the following is a correct way to catch an error generated by inv(A) when A is singular? A)
try inv(A); catch ME disp('Matrix is singular'); end B) if inv(A) == error; disp('Singular'); end
C) try inv(A); otherwise disp('Singular'); end D) catch inv(A); Answer: A Explanation: The try…catch block captures runtime errors; ME holds the exception object. Question 49. Which command creates a simple GUI button that displays “Press Me” using App Designer? A) Drag a Button component onto the canvas and set its Text property to “Press Me”. B) uicontrol('Style','pushbutton','String','Press Me') C) button('Press Me') D) guiButton('Press Me') Answer: A Explanation: In App Designer, UI components are added via drag‑and‑drop; setting the Text property changes the label. Question 50. Which toolbox function computes the fast Fourier transform of a signal x? A) fft(x) B) fourier(x) C) spectral(x) D) dft(x) Answer: A Explanation: fft implements the Cooley‑Tukey fast Fourier transform algorithm. Question 51. Which command returns the MATLAB version number as a string? A) version B) ver
C) y = [] ; y(1000) = 0; D) Both A and C Answer: D Explanation: Both zeros and assigning the 1000‑th element create a pre‑allocated vector; option C relies on automatic expansion but the final size is the same. Question 55. Which command creates a logical array L that is true for all elements of A that are either less than 0 or greater than 10? A) L = (A < 0) | (A > 10); B) L = (A < 0) && (A > 10); C) L = (A < 0) & (A > 10); D) L = (A <= 0) || (A >= 10); Answer: A Explanation: The element‑wise OR operator | combines the two logical conditions. Question 56. Which function converts a datetime array t to a numeric representation of days since Jan 1 2000? A) days(t - datetime(2000,1,1)) B) datenum(t) - datenum('2000- 01 - 01') C) Both A and B D) datevec(t) Answer: C Explanation: Both approaches compute the difference in days; days works directly with datetime objects, while datenum returns serial date numbers. Question 57. What does the command parfor i = 1:10, y(i) = i^2; end do?
A) Executes the loop iterations in parallel if a parallel pool is available B) Executes a normal for loop C) Throws an error because parfor cannot assign to y(i) D) Runs the loop on a GPU Answer: A Explanation: parfor distributes iterations across workers in a parallel pool, accelerating independent computations. Question 58. Which function creates a 5‑by‑5 identity matrix? A) eye(5) B) ident(5) C) diag(ones(5,1)) D) Both A and C Answer: D Explanation: eye(5) directly creates the identity matrix; diag(ones(5,1)) also produces it. Question 59. Which command computes the eigenvalues of matrix M? A) eig(M) B) eigen(M) C) svd(M) D) det(M) Answer: A Explanation: eig returns eigenvalues (and optionally eigenvectors). Question 60. In a script, which line will generate a syntax error?