-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatNest.m
27 lines (23 loc) · 1.16 KB
/
statNest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function [me, SD] = statNest(v)
% user-defined function statNest accepts input argument v, and has output
% arguments me and SD
me = AVG(v); % declares me variable and calls function AVG, passes v data
SD = StandDiv(v); % declares SD variable and calls function StandDiv,
% passes v data
function av = AVG(x) % defines AVG function, stores v data into a parameter
% reference variable x, sets function to variable av the output
% argument
n = length(x); % declares n variable, sets n to the # of elements in x
av = sum(x)./n; % declares av variable, sets it to sum of x / #elements
end
function sdiv = StandDiv(x) % defines StandDiv function, stores v data
% into a parameter reference variable x, sets the function to
% variable sdiv - the output argument
% Break the standard deviation expresion in multiple pieces...
n = length(x); % sample size
pnum = (x-me); % declares pnum variable, output is an array
pnumexp = (pnum).^2; % output is an array
sdiv = sqrt(sum(pnumexp)./(n-1)); % declares sdiv variable, sets it
% std deviation expression
end
end