MCQs on Variables and Data Types | MATLAB

  1. Which of the following is a valid variable name in MATLAB? a) 1stVar
    b) Var_1
    c) _Var
    d) 1_var
  2. In MATLAB, variable names must begin with which of the following characters?
    a) A number
    b) A letter
    c) A symbol
    d) A whitespace
  3. What is the maximum length of a variable name in MATLAB?
    a) 50 characters
    b) 63 characters
    c) 128 characters
    d) 100 characters
  4. Which of the following is a valid example of a MATLAB variable?
    a) 4Var
    b) Var_4
    c) Var!
    d) Var(4)
  5. MATLAB is case-sensitive. Which of the following are considered different variables?
    a) var and Var
    b) var_ and var
    c) _var and var
    d) None of the above

Scalars, Vectors, and Matrices

  1. A scalar in MATLAB is:
    a) A single value of any type
    b) A one-dimensional array
    c) A two-dimensional array
    d) A matrix
  2. Which of the following MATLAB code defines a vector?
    a) v = [1, 2, 3]
    b) v = (1; 2; 3)
    c) v = {1, 2, 3}
    d) v = [1; 2; 3]
  3. How would you create a 3×3 identity matrix in MATLAB?
    a) I = zeros(3, 3)
    b) I = eye(3)
    c) I = ones(3, 3)
    d) I = diag(3)
  4. What is the result of the following MATLAB operation:
    A = [1, 2; 3, 4]; B = [5, 6; 7, 8]; C = A * B?
    a) [19, 22; 43, 50]
    b) [23, 34; 67, 89]
    c) [19, 22; 43, 50]
    d) Error due to incompatible matrix sizes
  5. Which MATLAB command would you use to find the transpose of a matrix?
    a) transpose()
    b) inv()
    c) flip()
    d) .’

Common Data Types (double, char, logical)

  1. What is the default numeric data type in MATLAB?
    a) integer
    b) char
    c) double
    d) logical
  2. What does the MATLAB command char('a') return?
    a) 97
    b) ‘a’
    c) 1
    d) Error
  3. The MATLAB command logical(1) returns:
    a) true
    b) false
    c) 1
    d) 0
  4. Which of the following is a logical expression in MATLAB?
    a) x == 5
    b) x = 5
    c) x + 5
    d) x >
  5. What is the result of the following MATLAB operation:
    x = true; y = false; z = x & y?
    a) true
    b) false
    c) 1
    d) Error

Type Conversion

  1. Which MATLAB function converts a string to a double-precision value?
    a) int2str()
    b) str2num()
    c) double()
    d) num2str()
  2. What is the MATLAB command to convert a number to a character?
    a) num2char()
    b) num2str()
    c) str2char()
    d) char2num()
  3. Which of the following converts a number to a logical value in MATLAB?
    a) logical()
    b) str2double()
    c) double()
    d) num2log()
  4. If x = 10, which of the following commands will convert x to a string?
    a) num2char(x)
    b) char(x)
    c) str(x)
    d) num2str(x)
  5. What is the output of the following MATLAB code:
    y = double('3.14')?
    a) 3.14
    b) 51.14
    c) 51
    d) Error

Additional Questions

  1. What does the function isempty(x) do in MATLAB?
    a) Returns true if x is empty
    b) Converts x to an empty array
    c) Checks if x is a scalar
    d) Returns false if x is empty
  2. How do you create a logical array of size 3×3 with all elements set to true?
    a) true(3, 3)
    b) ones(3, 3)
    c) zeros(3, 3)
    d) logical(3, 3)
  3. Which function is used to check the type of a variable in MATLAB?
    a) varType()
    b) type()
    c) class()
    d) check()
  4. What will the expression size([1, 2; 3, 4]) return?
    a) 1
    b) 2
    c) [2, 2]
    d) [1, 4]
  5. What MATLAB function is used to create a matrix of all zeros?
    a) ones()
    b) zeros()
    c) eye()
    d) rand()
  6. In MATLAB, which of the following represents a 2×3 matrix?
    a) [1 2 3; 4 5 6]
    b) [1 2; 3 4]
    c) [1 2 3; 4 5]
    d) [1 2 3]
  7. What is the result of the operation size([1, 2, 3]) in MATLAB?
    a) [1, 3]
    b) [3, 1]
    c) [1, 1]
    d) Error
  8. Which function converts an integer value to a string in MATLAB?
    a) int2str()
    b) num2str()
    c) str2num()
    d) string()
  9. How do you check if a matrix is square in MATLAB?
    a) size(A) == size(B)
    b) ismatrix(A)
    c) all(size(A) == size(B))
    d) size(A, 1) == size(A, 2)
  10. What will be the output of the MATLAB code class(3.5)?
    a) ‘double’
    b) ‘int32’
    c) ‘single’
    d) ‘char’

Answer Key

QnoAnswer
1b) Var_1
2b) A letter
3b) 63 characters
4b) Var_4
5a) var and Var
6a) A single value of any type
7a) v = [1, 2, 3]
8b) I = eye(3)
9c) [19, 22; 43, 50]
10d) .’
11c) double
12b) ‘a’
13a) true
14a) x == 5
15b) false
16b) str2num()
17b) num2str()
18a) logical()
19d) num2str(x)
20c) 51
21a) Returns true if x is empty
22a) true(3, 3)
23c) class()
24c) [2, 2]
25b) zeros()
26a) [1 2 3; 4 5 6]
27a) [1, 3]
28b) num2str()
29d) size(A, 1) == size(A, 2)
30a) ‘double’

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top