0% found this document useful (0 votes)
3 views4 pages

MATLAB Command Quiz Questions

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

MATLAB Command Quiz Questions

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Model Question Paper

(1) Which command will return the corner elements of a 10-by-10 matrix A?
(a) A([1,end], [1,end])
(b) A([1,1], [end,end])
(c) A({[1,1], [1,end], [end,1], [end,end]})
(d) A(1:end, 1:end)

(2) Which command will return the fraction of positive numbers in a 10-by-10 matrix A?

(a) A(A > 0)/A


(b) numel(A > 0)/numel(A)
(c) sum(A > 0)/prod(size(A))
(d) nnz(A > 0)/numel(A)

(3) Which command will delete (completely remove) the last cell of a cell-array C?

(a) C{end} = [];


(b) C[end] = [];
(c) C(end) = [];
(d) C{end} = {[]};

(4) Which command will create a plot of acceleration vs. time (i.e., a vector time on the x-axis and
a vector acceleration on the y-axis)?
(a) plot(time, acceleration)
(b) plot(acceleration, time)
(c) plot([time, acceleration])
(d) plot([acceleration, time])

(5) Which command will give the standard deviation for each column in a 10-by-5 matrix Z?

(a) std(Z(:))
(b) std(std(Z))
(c) std(Z(1:5, :))
(d) std(Z)

(6) Which command should be executed to clear all variables from the Workspace without
clearing the Command Window or closing any figures?
A. clc
B. close all
C. clear all
D. clf
(7) You need to create a row vector x containing exactly 15 equally spaced points starting at 0 and
ending at 10. Which command is correct?
A. x = 0:15:10
B. x = linspace(0, 10, 15)
C. x = linspace(0, 15, 10)
D. x = 0:(10/14):10
(8) Given the matrix A = [10 20 30; 40 50 60; 70 80 90], what is the output of A(end, 2)?
A. 60
B. 80
C. 50
D. 90
(9) You have two vectors A = [1 2 3] and B = [4 5 6]. Which operation will calculate the element-
wise product (resulting in [4 10 18])?
A. A * B
B. A .* B
C. A * B'
D. dot(A, B)
(10) Which command creates a 2x2 array of 8-bit unsigned integers?
A. int8(zeros(2,2))
B. uint8([0 0; 0 0])
C. unsigned(2,2)
D. zeros(2, 2, 'uint8')
(11) You have a cell array C = {'Hello', [1 2; 3 4]}. Which command extracts the matrix contents [1
2; 3 4] so you can perform math on it?
A. C(2)
B. C{2}
C. C[2]
D. C.2
(12) Which function creates a datetime array representing the current date and time?
A. now
B. clock
C. datetime('now')
D. today
(13) You want to plot y vs x as red circles without a connecting line. Which syntax is correct?
A. plot(x, y, 'r-o')
B. plot(x, y, 'ro')
C. plot(x, y, 'circle', 'red')
D. scatter(x, y, 'r', 'LineStyle', '-')
(14) Before creating a surface plot using surf(X, Y, Z), which function is commonly used to create
the X and Y coordinate matrices from grid vectors?
A. griddata
B. meshgrid
C. repmat
D. matrix
(15) Which line of code correctly defines a function named calcStats that accepts an input data and
returns two outputs: avg and stDev?
A. function calcStats(data) = [avg, stDev]
B. function [avg, stDev] = calcStats(data)
C. def calcStats(data) return avg, stDev
D. [avg, stDev] = function calcStats(data)
(16) Consider the following code:
x = 5;
if x > 10
y = 1;
elseif x > 2
y = 2;
else
y = 3;
end
What is the final value of y?
A. 1
B. 2
C. 3
D. 0
(17) You need to pre-allocate a large array A to improve loop performance. Which practice is
recommended before entering a for loop that fills A?
A. A = [];
B. A = zeros(1000, 1);
C. A = null;
D. Do not define A; let it grow dynamically inside the loop.
(18) Which converts a number to string?
A. str2num
B. num2str
C. string2num
D. char2str
(19) Define structure s with field age = 25:
A. s(age)=25
B. [Link] = 25
C. struct(s,age,25)
D. s->age=25
(20) Current date and time:
A. sysdate
B. now
C. [Link]
D. currentdate
(21) Function name must match:
A. variable name
B. script name
C. file name
D. no requirement
(22) break keyword:
A. skips current iteration
B. stops the loop
C. restarts the loop
D. exits program

You might also like