{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# stats - errorMsg string invalid number of arguments notice...

This preview shows pages 1–2. Sign up to view the full content.

function [xbar, sigma] = stats(a) % XBAR(A) - compute mean and standard deviation % function [xbar, sigma] = fooBar(a)... just for kicks, try this :-) % (c) 2000 g.m.dick % % the purpose of this function is to compute the: % - mean % - standard deviation (optionally) % of the input array % % data dictionary % =============== % argument type I/O description % ---------------------------------------------------------------------- % a array input the array to be analyzed % xbar scalar output the atithmetic mean of the input % sigma scalar output the standard deviation of the input % ______________________________________________________________________ % variable type description % ---------------------------------------------------------------------- % sum scalar sum of data or ... % sum of squared deviations % i, j scalar loop indices % nRow, nCol scalar number of rows/columns in the input array

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % errorMsg string invalid number of arguments notice % % synopsis % ======== % - verify arguments - abort if error % - compute average = sum(a)/"n" % - if two arguments % - compute standard deviation = rootMeanSquared deviation % - return % % verify valid number of arguments - abort if incorrect errorMsg = nargchk(1,1,nargin); error(errorMsg) e % compute the average [nRow, nCol] = size(a); % extract array size sum = 0; for i = 1: nRow % accumulate the sum for j = 1: nCol sum = sum + a(i,j); end end xbar = sum./(i*j); % the mean x % if two arguments - compute standard deviation if nargout == 2 sum = 0; for i = 1: nRow % accumulate the sum of the squared deviations for j = 1: nCol sum = sum + (xbar - a(i,j)).^2; end end sigma = sqrt(sum./(i*j)); % the rootMeanSquared deviation end e e...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

stats - errorMsg string invalid number of arguments notice...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online