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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
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

This note was uploaded on 04/05/2010 for the course CHEMENG 05078870 taught by Professor Mustafa during the Spring '10 term at Ege Üniversitesi.

Page1 / 2

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online