MATLAB Questions and Answers – Managing Variables

«
»

This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “Managing Variables”.

1. What will be the output when the following code is written in MATLAB?

advertisement
 u=sin(10);v=pi;whos

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
View Answer

Answer: a
Explanation: ‘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   
advertisement
advertisement

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
View Answer

Answer: a
Explanation: 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.
advertisement

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
View Answer

Answer: b
Explanation: 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.
advertisement

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
View Answer

Answer: a
Explanation: 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.
advertisement

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
View Answer

Answer: c
Explanation: 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
View Answer

Answer: d
Explanation: ‘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   

7. From the following desktop view of workspace, choose the correct code.
matlab-questions-answers-managing-variables-q7
a) a=10;b=’pi’;syms c; d=[1,2;0;4];
b) a=10;b=’pi’;syms c; d=[1,2;0,4];
c) a=10;b=pi;syms (c); d=[1,2;0,4];
d) a=10;b=’pi’;syms c; d=[1,2;0,4];
View Answer

Answer: a
Explanation: ‘b’ is a character variable, within inverted commas. ‘a’ is a double variable. ‘c’ is a symbolic object while ‘d’ is a 2*2 matrix. The declaration of the variables is in accordance to the following code:
a=10;b=’pi’;syms c; d=[1,2;0;4];

8. What is the size of double and symbolic variables holding integer constants?
a) 8 bytes and 16 bytes
b) 16 bytes and 112 bytes
c) 32 bytes and 26 bytes
d) 23 bytes and 112 bytes
View Answer

Answer: a
Explanation: The size of double variables holding integer constants is 8 bytes. The size of symbolic variables is 112 bytes. These are predefined data type sizes in MATLAB.

9. Choose the correct option as an inference from the following workspace view.
matlab-questions-answers-managing-variables-q9
a) ‘ans’, ‘p’ and ‘ap’ are double variables
b) ‘ans’ and ‘p’ are double variables while ‘c’ is a character variable
c) ‘ap’ is symbolic object, ‘c’ is a double variable
d) ‘c’ is a symbolic character
View Answer

Answer: b
Explanation: It is to be noted that ‘ans’ and ‘p’ are double integer variables, ‘c’ is a character variable while ‘ap’ is a symbolic object.

10. What is the difference between who and whos command?
a) The former shows the names of the variables being used while the latter shows the details of the variables in the ongoing program
b) The latter shows the the names of the variables being used while the former shows the details of the variables in the ongoing program
c) No difference at all
d) There is no such function as who and whos
View Answer

Answer: a
Explanation: The function ‘who’ shows the names of the variables used. The function ‘whos’ shows the details of the variables in the ongoing program but it doesn’t show the attributes of the variables.

11. What is the conclusion from the following code?

 >>whos
 Name     Size         Bytes    Class     Attributes
 ans      1x1            8      double              
 ap       1x1          112  	sym              
 c        1x2            4      char
 p        1x1            8      double

a) The function ‘whos’ doesn’t show the values of the variables being used
b) The value of each variable is 0
c) The function ‘who’ is more effective than ‘whos’
d) Nothing can be concluded
View Answer

Answer: a
Explanation: The function ‘whos’ doesn’t show the values of the variables being used. Instead it will display the size, bytes and class of the variable in use. It is no useful than the function ‘who’ since it only shows the name of the variable used, when invoked.

12. What are Max and Min in the Workspace shown below?
matlab-questions-answers-managing-variables-q12
a) They show the maximum and minimum value of the variable
b) The show the maximum and minimum length of the variable
c) They show the maximum and minimum value present in an array
d) They show the median and mode of the variable
View Answer

Answer: c
Explanation: The columns ‘Min’ and ‘Max’ show the maximum and minimum values present in a variable. So, if the variable is an array, the ‘Min’ and ‘Max’ may or may not be same. Here, a is a variable having a single constant value so they are same.

13. How would you express a pi as a character and an integer? Choose the correct code.
a) a=pi;b=’pi’;
b) a=22/7; b=pi;
c) a=3.1415; b=22/7;
d) a=3.1429;b=’pi’;
View Answer

Answer: a
Explanation: After entering the code in MATLAB, the workspace view is:
matlab-questions-answers-managing-variables-q13
A character variable is stored by declaring the character value within a pair of single inverted commas. An integer variable is stored by simply declaring the variable with the integer value. pi is stored in MATLAB as an integer value itself of 3.1416.

Sanfoundry Global Education & Learning Series – MATLAB.

To practice all areas of MATLAB, here is complete set of 1000+ Multiple Choice Questions and Answers.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter