-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZNormalize.m
More file actions
46 lines (42 loc) · 1.17 KB
/
Copy pathZNormalize.m
File metadata and controls
46 lines (42 loc) · 1.17 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
% -----------------------------------------------------------------
% ZNormalize.m
% -----------------------------------------------------------------
% Programmer: Americo Cunha Jr
% americo.cunhajr@gmail.com
%
% Originally programmed in: Jun 29, 2026
% Last update in: Jun 29, 2026
% -----------------------------------------------------------------
% Computes the z-score normalized variable.
%
% Z = ZNormalize(X)
% Uses the sample mean and sample standard deviation of X.
%
% Z = ZNormalize(X,mu,sigma)
% Uses the supplied mean and standard deviation.
%
% Inputs:
% X : input array
% mu : mean (optional)
% sigma : standard deviation (optional)
%
% Output:
% Z : z-score normalized array
%
% Formula:
% Z = (X - mu)/sigma
% -----------------------------------------------------------------
function Z = ZNormalize(X,mu,sigma)
if nargin < 2
mu = mean(X(:));
end
if nargin < 3
sigma = std(X(:));
end
% Avoid division by zero
if sigma < eps
sigma = 1;
end
Z = (X - mu)/sigma;
end
% -----------------------------------------------------------------