function y=nanstd(x)
%y=nanstd(x)
%
%calculate the std of a matrix w/ nan's in it, otherwise just the
%same as the normal std function.

[M,N]=size(x);

if M==1 | N==1

   if isempty(find(~isnan(x) & ~isinf(x))) 
   y=nan;
   else
   y=std(x(find(~isnan(x) & ~isinf(x))));
   end;

elseif M>1 & N>1

   for i=1:N
   
   if isempty(find(~isnan(x(:,i)) & ~isinf(x(:,i))))
   y(i)=nan;
   else
   y(i)=std(x(find(~isnan(x(:,i)) & ~isinf(x(:,i))),i));
   end;

   end; %for i loop

end;
