eeg_linfit.m

来自「Matlab下的EEG处理程序库」· M 代码 · 共 58 行

M
58
字号
function [p] = eeg_linfit(p)

% EEG_LINFIT - returns slope/intercept of linear fit
%
% USEAGE: [p] = eeg_linfit(p)
%
% p is the eeg_toolbox struct.  For this function, the fields
% required are:
%
%   p.volt.data - voltage data matrix (Npoints,Nelec)
%   p.volt.timeArray - voltage sample points (msec)
%
% Returns slope and intercept matrices (Npoints,Nelec)
% for linear fit of each electrode into fields of p:
%
%   p.volt.fitslope
%   p.volt.fitintercept
%
% The column vectors of slope/intercept hold constant 
% values.  So, the linear fit data can be generated by:
% 
% y = p.volt.fitslope .* p.volt.timeArray + p.volt.fitintercept;
% 
% Where necessary, the p.volt.timeArray is replicated
% across columns for each electrode to enable this calculation
% 

% $Revision: 1.3 $ $Date: 2003/04/07 06:12:02 $

% Licence:  GNU GPL, no implied or express warranties
% History:  07/00, Darren.Weber@flinders.edu.au
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% volt.timeArray is essentially a column vector, but
% operations in the eeg_toolbox may replicate across N columns
time = p.volt.timeArray(:,1);

slope = zeros(1,size(p.volt.data,2));
intercept = slope;

for elec = 1:size(p.volt.data,2),
    
    y = polyfit(time,p.volt.data(:,elec),1);
    slope(1,elec) = y(1);
    intercept(1,elec) = y(2);
end

% make sure that volt.timeArray is same size as volt.data
if ~isequal(size(p.volt.timeArray),size(p.volt.data)),
    p.volt.timeArray = repmat(p.volt.timeArray(:,1),1,size(p.volt.data,2));
end

p.volt.fitslope = repmat(slope,size(p.volt.data,1),1);
p.volt.fitintercept = repmat(intercept,size(p.volt.data,1),1);

return

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?