Home > eeg > egis > data_utils > zeromean.m

zeromean

PURPOSE ^

outdata = zeromean(indata, start, stop)

SYNOPSIS ^

function outdata = zeromean(indata, start, stop)

DESCRIPTION ^

outdata = zeromean(indata, start, stop)
  
Subtracts the mean value from each column in the matrix from each value 
in each column. Start and stop sample values are optional. Indata is a
NSamps x NChans matrix, such as that returned by rd_onetr_allch (c.f.).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function outdata = zeromean(indata, start, stop)
0002 %outdata = zeromean(indata, start, stop)
0003 %
0004 %Subtracts the mean value from each column in the matrix from each value
0005 %in each column. Start and stop sample values are optional. Indata is a
0006 %NSamps x NChans matrix, such as that returned by rd_onetr_allch (c.f.).
0007 %
0008 
0009 %Modification History
0010 %  Written 6/126/95  PJ
0011 %  Additional error checking added 10/11/95 by BCR
0012 %  Modified to properly handle the case of no start and stop entered RS 10/31/95
0013 %  Fixed some of the other error checks    RS 10/31/95
0014 
0015 if (nargin < 1) | (size(indata,1)==0) | (size(indata,1)==0)
0016     error('Function requires at least one argument, a rectangular matrix.');
0017     end;
0018     
0019 if nargin == 1
0020      start = 1; 
0021      stop = size(indata,1);
0022      end;
0023 if nargin == 2
0024     if start >= size(indata,1)
0025         error('Start argument must be less than # of data matrix rows.');
0026     end;
0027     stop = size(indata,1);
0028     end;
0029 if nargin >= 3
0030     if start >= size(indata,1)
0031         error('Start argument must be less than # of data matrix rows.');
0032     end;
0033     if stop > size(indata,1)
0034         error('Stop argument must be less than # of data matrix rows.');
0035     end;
0036     if stop <= start
0037         error('Stop argument must be greater than start argument.');
0038     end;
0039     if nargin > 3
0040         disp('Ignoring arguments beyond the third.');
0041     end;
0042     end;
0043 
0044 outdata = zeros(size(indata));
0045 
0046 datamean = mean(indata(start:stop,:));  % returns a row-vector with mean of each column
0047 datamean = ones(size(indata,1),1) * datamean; % turns mean vector into matrix
0048 
0049 outdata = indata - datamean;
0050 return

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003