
function m = median_nan(a);


% version of median function that returns median
% of non-NaN elements;

m = median(a);
inan = find(isnan(m));
if isempty(inan)
  return
end

[mrow ncol] = size(a);
if mrow == 1 | ncol == 1
  m = median(a(find(~isnan(a))));
  return
end

for ii = inan            
  m(ii) = median(a(find(~isnan(a(ii))),ii));
end    
