Matlab Creating and Using Vectors Quiz

Matlab
0 Passed
0% acceptance

35 fundamental questions on creating, indexing, and manipulating row and column vectors in MATLAB.

35 Questions
~70 minutes
1

Question 1

Which command creates a row vector containing the numbers 1, 2, and 3?

A
v = [1, 2, 3]
B
v = [1; 2; 3]
C
v = (1, 2, 3)
D
v = {1, 2, 3}
2

Question 2

How do you create a column vector with elements 4, 5, and 6?

A
v = [4; 5; 6]
B
v = [4, 5, 6]
C
v = [4:5:6]
D
v = column(4, 5, 6)
3

Question 3

What does the expression '1:5' generate?

A
A row vector: [1, 2, 3, 4, 5]
B
A column vector: [1; 2; 3; 4; 5]
C
The number 5
D
A random number between 1 and 5
4

Question 4

What is the result of '1:2:7'?

A
[1, 3, 5, 7]
B
[1, 2, 3, 4, 5, 6, 7]
C
[1, 2, 7]
D
[2, 4, 6]
5

Question 5

How do you access the second element of a vector named 'v'?

A
v(2)
B
v[2]
C
v{2}
D
v.2
6

Question 6

What happens if you try to access index 0 in MATLAB (e.g., v(0))?

A
It throws an error because indexing starts at 1
B
It returns the first element
C
It returns the last element
D
It returns 0
7

Question 7

If v = [10, 20, 30], what is the result of 'v + 5'?

A
[15, 25, 35]
B
[10, 20, 30, 5]
C
Error
D
15
8

Question 8

How do you transpose a row vector 'r' into a column vector?

A
r'
B
transpose(r)
C
Both A and B
D
flip(r)
9

Question 9

What is the result of '[1, 2] + [3, 4]'?

A
[4, 6]
B
[1, 2, 3, 4]
C
Error
D
10
10

Question 10

Which command creates a vector counting down from 10 to 1?

A
10:-1:1
B
10:1
C
1:10
D
countdown(10, 1)
11

Question 11

What is the length of the vector generated by '0:0.5:2'?

A
5
B
4
C
3
D
2
12

Question 12

If v = [1, 2, 3, 4, 5], what does 'v(2:4)' return?

A
[2, 3, 4]
B
[2, 4]
C
[1, 2, 3]
D
[3, 4, 5]
13

Question 13

How do you concatenate two row vectors 'a' and 'b' horizontally?

A
[a, b]
B
[a; b]
C
a + b
D
cat(a, b)
14

Question 14

What is the result of 'v(end)'?

A
The last element of the vector
B
The length of the vector
C
The first element
D
Error
15

Question 15

If you try to add a row vector of length 3 to a column vector of length 3 (e.g., [1,2,3] + [1;2;3]), what happens in modern MATLAB?

A
It produces a 3x3 matrix (Implicit Expansion)
B
It throws an error due to dimension mismatch
C
It adds the first elements only
D
It converts the column to a row and adds them
16

Question 16

Which function returns the number of elements in a vector?

A
length(v)
B
size(v)
C
count(v)
D
numel(v)
17

Question 17

How do you replace the third element of vector 'v' with the value 99?

A
v(3) = 99;
B
v[3] = 99;
C
v{3} = 99;
D
replace(v, 3, 99);
18

Question 18

What does 'linspace(1, 10, 3)' generate?

A
[1, 5.5, 10]
B
[1, 2, 3]
C
[1, 10, 3]
D
[1, 4, 7]
19

Question 19

If v = [10, 20, 30, 40], what is 'v([1, 3])'?

A
[10, 30]
B
[10, 20, 30]
C
[20, 40]
D
Error
20

Question 20

What is the result of 'v = []'?

A
Creates an empty vector
B
Deletes the variable v
C
Creates a vector with one zero
D
Error
21

Question 21

How do you delete the second element of a vector 'v'?

A
v(2) = [];
B
delete(v(2));
C
v(2) = 0;
D
remove(v, 2);
22

Question 22

What is the default step size for the colon operator if none is specified (e.g., 1:5)?

A
1
B
0
C
0.1
D
It depends on the numbers
23

Question 23

Can a vector contain a mix of numbers and strings in MATLAB?

A
No, standard arrays must be homogeneous
B
Yes, always
C
Only if it is a row vector
D
Yes, but they are converted to ASCII
24

Question 24

What does 'v(end-1)' access?

A
The second to last element
B
The last element minus 1
C
The element before the start
D
Error
25

Question 25

If v = [1, 2, 3], what is 'v * 2'?

A
[2, 4, 6]
B
[1, 2, 3, 1, 2, 3]
C
Error
D
2
26

Question 26

Which command creates a vector of five zeros?

A
zeros(1, 5)
B
zeros(5)
C
[0] * 5
D
0:5
27

Question 27

What is the result of 'sum([1, 2, 3])'?

A
6
B
[1, 2, 3]
C
3
D
1
28

Question 28

How do you reverse a vector 'v'?

A
v(end:-1:1)
B
reverse(v)
C
v(-1)
D
inv(v)
29

Question 29

What happens if you assign a value to an index outside the current bounds? (e.g., v(10) = 5 where v has length 3)

A
MATLAB expands the vector and fills intermediate spots with 0
B
Error: Index out of bounds
C
It ignores the assignment
D
It adds it to the end regardless of index
30

Question 30

Which operator performs element-wise division?

A
./
B
/
C
\
D
div
31

Question 31

If A = [1, 2] and B = [3, 4], what is 'A .* B'?

A
[3, 8]
B
11
C
[1, 2, 3, 4]
D
[4, 6]
32

Question 32

What is the result of 'ones(3, 1)'?

A
A column vector of three 1s
B
A row vector of three 1s
C
A 3x3 matrix of 1s
D
The number 1
33

Question 33

How do you check if a vector is empty?

A
isempty(v)
B
v == []
C
empty(v)
D
check(v)
34

Question 34

What is the result of 'min([5, 2, 9])'?

A
2
B
5
C
9
D
1
35

Question 35

If v = [10, 20, 30], what is 'v( [true, false, true] )'?

A
[10, 30]
B
[10, 20]
C
[20]
D
Error

QUIZZES IN Matlab