function [out] = std2_3d(in);

%takes std of a vector ignoring NaN entries
%designed for a 3d matrix

if length(size(in)) > 3 | length(size(in)) < 3;
    error('This script is designed for 3d matrices only')
end

[N, NN, NNN]=size(in);
for nn=1:NN;
    for nnn=1:NNN;
        data=squeeze(in(:,nn,nnn));
        data=data(find(isnan(data) == 0 )); %remove NaN
        out(nn,nnn)=std(data);
        clear data
    end
end

