Commands for Parsing Input and Output

This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “Commands for Parsing Input and Output”.

1. What is the working of the nargin keyword?
a) Returns the number of inputs to a function as an output of the same function
b) Gets assigned to a value equal to the number of inputs of a function
c) Gets assigned to a value equal to the number of inputs+1 of a function
d) Gets assigned to a value equal to the number of inputs-1 function

2. What is the working of the varargout command?
a) Returns a 1*N cellular matrix
b) Returns a 1*N cell array of outputs
c) Returns a 1*N cell array of inputs given
d) Doesn’t exist

3. What is the working of the nargout command?
a) Gets assigned to a number which is equal to the number of outputs-1 sought from a subfunction
b) Gets assigned to a number which is equal to the number of outputs-1 sought from a function
c) Gets assigned to a number which is equal to the number of outputs sought from a function
d) Gets assigned to a number which is equal to the number of outputs+1 sought from a function

4. What is the working of the varargin command?
a) takes 1*N inputs after the defined inputs in a function
b) takes N*1 inputs after the defined inputs in a function
c) takes N*N inputs after the defined inputs in a function
d) takes 1*1 inputs after the defined inputs in a function

5. What is the output of the following command?

```function s= average(varargin)
celldisp(varargin)
s=sum(varargin)
end
p=average(1:3)```

a) Error in sum
b) Error using varargin in function definition
c) Error calling the average function
d)

```    1 2 3
p=6```

6. What is the output of the following command?

```function wish= ful(p,varargin)
celldisp(p)
wish=sin(varargin{1})
end
p=ful(1:3)```

a) Error in calling the function
b) Error in celldisp
c) Error in the function definiton
d) Error in the wish variable

7. What is the output of the following command?

```function mad= heart(p,varargin)
disp(p)
wish=sin(varargin{0})
end
p=heart(1:3,0)```

a) Error in wish command
b) Error while calling heart command
c) Error while calling disp command
d)

```     1 2 3
wish=0```

8. What is the output of the following command?

```function mad= rush(p,varargin)
disp(p)
wish=cos(varargin[0])
end
p=rush(1:3,pi/2)```

a) Error due to element index
b) Error due to syntax of varargin
c)

```  1 2 3
wish=0```

d) Error due to disp()

9. What is the output of the following code?

```function mad= rush(p,varargin)
disp(p)
wish=cos(varargin{1})
end
p=rush(1:3,Inf)```

a) Error due to Inf
b) -1
c)

```    p{1}= 1 2 3
wish=0```

d)

```     p{1}= 1 2 3
wish=NaN```

10. What is the output of the following code?

```function maha= orchid(polo,varargin)
disp(polo)
wish=sum(varargin{1,2})
end
p=rush(-1:1,Inf)```

a) Logical error in varargin
b) Syntactical error in varargin
c)

```     p{1}=-1 0 1
wish=0```

d) No output

11. What is the output of the following code?

```function [die,absdif] = BDO(y,x)
die = y-x;
if nargout > 1
disp('Boo !')
absdif = abs(die);
end
end
[p,q]=BDO(Inf,Inf)```

a)

```     Boo!
p=NaN
q=NaN```

b)

```     Boo!
p=0
q=0```

c) Error
d) p=NaN

12. What is the output of the following code?

```function [die,af] = Bod(y,x)
die = y*x;
if nargout < 1
error('Boo !')
else
disp(‘Yo !’)
af = abs(die);
end
end
[p]=Bod(1,[1 -2])```

a) Error with Boo! displayed
b)

```     Yo !
p=1```

c)

```     Yo !
p=2```

d)

```     Yo !
p=-2```

13. What is the output of the following code?

```function [die,af] = lola(y,x)
die = y*x;
if nargout < 1
error('Boo !')
else
disp(‘Yo !’)
af = abs(die);
end
end
p=lola(1,[1 -2])```

a) Error with Boo ! written
b)

```     Yo !
p=-2```

c)

```     Boo !
p=-1```

d)

```     Boo !
p=1```

14. A function ______________
a) can be run in the command window by defining it in the window itself
b) can be run in the command window by defining it in a cpp file
c) can be run in the command window by defining it in a script file
d) can be run in the script file by defining it in the command window

15. What is the output of the following code?

```function c = addem(ap,q)
p=nargn-1
switch p
case 2
c = ap*q;
case 1
c = sin(q)
otherwise
c = 0;
end

a) 2
b) Error due to too many inputs
c) 28
d) Error due to nargn

16. The working of the varargin command is dependent on the nargin command implicitly.
a) True
b) False

17. The nargout command is dependent on the number of outputs sought.
a) True
b) False

18. What is the output of the following command?

```function eclairs= honey(p,q)
narginchk(2,5)
disp(‘Yo, G!’)
c=q+p;
end
honey(1)```

a) Syntactical Error
b) Yo, G!
c) input error
d) 2 3 4 5

19. What is the output of the following command?

```function p= marie(p,q)
narginchk[2,3]
disp(‘Yo, G!’)
a=p+q
end
marie(1)```

a) Syntactical Error in narginchk
b)

```    Yo, G!
a=1```

c) Input error in narginchk
d) 2 3 4 5…Inf

20. What is the output of the following command?

```function ca= ola(p,q)
narginchk(0,1)
disp(‘Stick!’)
o=p-q;
end
ola(1,2)```

a) o=-1
b) o=1
c) Error in inputs
d) Syntactical error while calling function

21. What is the output of the following command?

```function pu= hu(p,varargin)
narginchk(0,1)
disp(‘Stick!’)
o=sin(varargin{1});
end
ola(1,p/2)```

a) Error due to line 2
b) Error due to line 5
c) Error due to syntax
d)

```     Stick!
o=1```

22. The narginchk command can limit the size of which cellular array?
a) fun
b) rand(2)
c) eye(3)
d) varargin

23. The nargoutchk command limits the length of which cellular array?
a) varargout
b) i(2)
c) random(69)
d) laplace(s)

24. The following operation results in?

`narginchk(2,Inf)`

a) Error due to Inf
b) Limits the length of nargin from 2 to Inf
c) Logical Error
d) Limits the length of varargin from 1 to Inf

25. The following operation result in

```Function p= ol(q,varargin)
narginchk(45,Inf)```

a) Error due to Inf
b) The range of the varargin array becomes (44,Inf)
c) The range of the varargin array becomes (45,Inf)
d) The range of the varargin array becomes [45,Inf]

26. The following operation results in

```Function p= ol(q,varargin)
narginchk(45,NaN)
end```

a) Error due to NaN
b) Syntactical error
c) Logical Error
d) Nothing happens

27. What is the minimum number of arguments after the following operation occurs in any function?

`narginchk(-2,0)`

a) 0
b) 1
c) -2
d) Error