function [stdx,stdy]=nanstd2(x,y)
% function nanstd2
%
% usage: [stdx,stdy]=nanstd2(x,y)
%
% calculates standard deviation of x and y over data present at both data sets
% x and y can contain NaN
% they can have 1, 2 or 3 dimensions
% but they must be the same size
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
% Copyright (C) 2006, Aida Alvera-Azcarate
% Author: Aida Alvera-Azcarate
mask=isnan(x) | isnan(y);
indy=find(~mask);%finds ones
x=x(indy);
y=y(indy);
mX=mean(x);
mY=mean(y);
xp=x-mX;
yp=y-mY;
stdx=sqrt(mean(xp.^2));
stdy=sqrt(mean(yp.^2));