function [ out ] = nancorrcoef(x_set, y_set )
%Calculates the correlation coefficient of data in matrix form with NaNs
%   

if size(x_set) ~= size(y_set);
    error('Inputs are different sizes')
end

x_linear = reshape(x_set, [], 1); %converts matricies to vectors
y_linear = reshape(y_set, [], 1);

xy_combo = [x_linear, y_linear];
xy_nonan_combo = xy_combo(~any(isnan(xy_combo),2),:); %removes nan values

if isempty(xy_nonan_combo);
    out = [];
else
    cc_xy = corrcoef(xy_nonan_combo(:,1), xy_nonan_combo(:,2));
    out = cc_xy(1,2);
end


end

