MATLAB Multiple Choice Questions on “Managing Variables”.
1. What will be the output when the following code is written in MATLAB?
a) u and v are double with 8 bytes
b) u and v are symbolic objects
c) error
d) u and v are double arrays
Answer: a
Clarification: ‘sin 10’ and ‘pi’ are numeric values which will be generated as double data type in MATLAB.
Output: Name Size Bytes Class Attributes
u 1x1 8 double
v 1x1 8 double
2. What is the disadvantage of the whos function in MATLAB?
a) It does not show the values of the variable
b) It does not show the size of the variable
c) It does not show the class of the variable
d) It does not show the name of the variable
Answer: a
Clarification: whos returns the name, size, bytes and class of the variables used in the current program. To get the value of any variable, we need to type the variable and press Enter.
3. What will be the output of the following code?
A=100; if(A>99) clear A; end
a) A never gets stored in MATLAB
b) A is first stored and then removed from workspace
c) Error
d) A is retained in the workspace
Answer: b
Clarification: A will be stored due to the first line of code. When the if structure is invoked, the variable will be deleted from the program due to the clear function.
4. What is the replacement for the whos function?
a) Workspace window
b) Command window
c) Current folder window
d) Remembering all the variables used
Answer: a
Clarification: The workspace window constantly gets updated with inclusion of any variable in the program. It shows the Value, Size, Bytes, Class and many other attributes of the variables used. Hence it is more useful than the whos function.
5. What does the Workspace show?
a) Attributes of variables, functions from command window
b) Attributes of variables, script files from command window
c) Attributes of variables, script files, functions from command window
d) Attributes of variables from command window
Answer: c
Clarification: The workspace window shows the attributes of variables, script files, functions from the command window for an ongoing program. It is more descriptive than the whos function.
6. What is the output of the following code?
a=10; b=10; c=’pi’; whos
a) The output will show all double variables
b) The output will show a and b as double and c as symbolic object
c) The output will show a and b as symbolic object and c as char
d) The output will show a and b as double variables and c as char variables
Answer: d
Clarification: ‘a’ and ‘b’ will be stored as double variables with a=10 and b=10 while c will be stored as a character variable as c=pi.
Output:
Name Size Bytes Class Attributes a 1x1 8 double b 1x1 8 double c 1x2 4 char
