Commit ec90b232 authored by Meryem Ayse Yucel's avatar Meryem Ayse Yucel
Browse files

Create hmrR_PreprocessIntensity_NAN.m

new function to replace NAN by spline interpolation of the nonnan values
parent 4e5d3052
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
% SYNTAX:
% intensity = hmrR_PreprocessIntensity_NAN( intensity )
%
% UI NAME:
% hmrR_PreprocessIntensity_NAN
%
% DESCRIPTION:
% replace NAN by spline interpolation of the nonnan values
%
% INPUT:
% intensity - SNIRF data type where the d matrix is intensity
%
% OUTPUT:
% intensity - SNIRF data type where the d matrix is intensity
%
% USAGE OPTIONS:
% Intensity_to_Intensity: d = hmrR_PreprocessIntensity_NAN(data)


function d = hmrR_PreprocessIntensity_NAN( intensity)


for ii=1:length(intensity)
    d = intensity(ii).GetDataTimeSeries();
    
    if ~isempty(find(isnan(d)))
        
        for j = 1:size(d,2)
            foo = d(:,j);
            if ~isempty(find(isnan(foo)))
                
                xdata = (1:length( foo))';
                d(:,j) = interp1(xdata(~isnan( foo)), foo(~isnan( foo)),xdata,'spline');
                
            end
        end
        
    end
    intensity(ii).SetDataTimeSeries(d);
end