Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Write a function that accepts a variable number of input parameters using the cell array varargin, and outputs a variable number of arguments using the cell array varargout.

1 Ansicht (letzte 30 Tage)
Write a function that accepts a variable number of input parameters using the cell array varargin, and outputs a variable number of arguments using the cell array varargout. Your function should examine each input argument in varargin to make sure it is numeric. If it is not numeric it should be ignored. If it is numeric, it should be added to a running total and each element counted. Your function should return three items: the count of numbers passed in to the function, the sum of the numbers, and the average of the numbers. Note: the numeric arguments passed in may be arrays, in which case you will need to deal with each of the numeric entries individually.
To test your function, you should write a test program that calls your program. If you call your program with the following data, your answers should be as shown below:
Data: a=5; b=[1 2 3 4; 5 6 7 8; 9 10 11 12]; c=[1 2 3];
Result: Count = 16, Sum = 89, Average = 5.5625
Be sure to handle the case where the function is called with more output arguments than what your function is designed to handle. Your test program should try calling your function with one, two, three and four output arguments. We won’t pass in any arrays with more than two dimensions, but you will need to be careful when summing the numbers in an array.

Antworten (1)

Vivek Selvam
Vivek Selvam am 7 Nov. 2013
doc varargin
doc varargout
doc is*
should help you get started.

Diese Frage ist geschlossen.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by