You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: histn.m
    path of file: ./repos/spinw/swfiles/+ndbase
    
    the code of the file until where you have to start completion: function [Ysum, Nsum, Cbin] = histn(X, Y, varargin)
% calculates histo
    
function for outliers
nanIdx = any(isnan(Y),2);
anynan = any(nanIdx);
% create an extra fake bin to sum up pixels with NaN coordinates, it is
% faster than to call accumarray with X(~nanIdx,:)
if anynan
    %X(nanIdx,2:end