| A similar function builds the varargout array using diagonals of a 5-by-5 matrix: function varargout = byDiag(a) varargout{1} = ' With VARARGOUT constructed by diagonal for k = -4:4 varargout{k + 6} = diag(a, k); end Call the function with five output variables. Again, MATLAB assigns elements of varargout according to the manner in which it was constructed within the function: [text d1 d2 d3 d4] = byDiag(magic(5)) text = With VARARGOUT constructed by diagonal ... d1 = 11 d2 = 10 18 d3 = 4 12 25 d4 = 23 6 19 2 Checking the Number of Input Arguments The nargin and nargout functions enable you to determine how many input and output arguments a function is called with. You can then use conditional statements to perform different tasks depending on the number ofarguments. For example, function c = testarg1(a, b) if (nargin == 1) c= a.A2; |