function  [out] = sergeiRemoveNaNs (inarr,dim)
% This function scans a two-column array along the dimension dim and removes the rows
% that contain NaNs
d=max(size(inarr));
k=1;
for i=1:d
    if isnan(inarr(i,dim))==0
        arr(k,:)=inarr(i,:);
        k=k+1;
    end
end    
out = arr;