For example, the contents of stats.m might be:
% % "stats.m" (function file) % Usage: [ xbar, std_dev ] = stats(x,n) % to average the first n elements of vector x. function [xavg,s] = stats(x,n) tot=0; totsq=0; for i=1:n tot = tot+x(i); totsq = totsq +x(i)^2; end xavg = tot/n; if n > 1 s = sqrt(totsq - tot^2/n)/(n-1))Last Update: September 25, 2000
[Mathlab Home | Math]