What is the output of the following command? [code]function s= average(varargin) celldisp(varargin) s=sum(varargin) end p=average(1:3) [/code]

What is the output of the following command?
Code:
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
 
Answer: a
Explanation: The input is acellular array called varargin. The input to the sum function in the average function is should be varargin{1} to indicate which element of the array varargin is to be taken.
 

Tìm kiếm

Back
Top