IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
assert_meancentered.m
Go to the documentation of this file.
1 %>@ingroup misc assert
2 %> @file
3 %> @brief Checks whether the columns of X have mean zero up to a certain tolerance.
4 %>
5 
6 %> @param X Input matrix
7 %> @param tolerance =0.0001 . A value of 0.0001 means that each variable mean needs to be <= 0.01% * its maximum absolute value
8 %> @return Nothing. If fails, wil generate an error.
9 function assert_meancentered(X, tolerance)
10 if nargin < 2 || isempty(tolerance)
11  tolerance = 0.0001;
12 end;
13 
14 extremes = max(abs(X), [], 1);
15 mm = mean(X, 1);
16 idx = find(abs(mm) > extremes*tolerance); %#ok<*EFIND>
17 if ~isempty(idx)
18  irerror(sprintf('X matrix is not mean-centered, for example, %g mean is not acceptable!', mm(idx(1))));
19 end;
function irerror(in s)
function assert_meancentered(in X, in tolerance)