No BSD License  

Highlights from
REMNAN

from REMNAN by Karsten Shein
Removes missing values jointly from 2 vectors.

remnan(x,y,t)
function [x1,y1] = remnan(x,y,t)
% FUNCTION REMNAN: [x1,y1] = remnan(x,y,t)
% Returns two series with NaNs removed.
% x and y are original vectors of the same size
% x1 and y1 are the post-processed vectors (x and y, respectively).
%
% t is a scalar operator:
%     1 = remove the values in both series corresponding to the missing
%         numbers in the first series (x).
%     2 = remove the values in both series corresponding to the missing
%         numbers in the second series (y).
%     3 = remove values from both series corresponding to missing values
%         in both series (x and y). DEFAULT IF t IS NOT PROVIDED
%     Any other number = remove the NaNs from each series independently
%
%   To simply remove the missing numbers from a series you may call this 
% m-file as y = remnan(x); or use the equation: y = x(~isnan(x));
%
% In the format x1 = remnan(x,y,t), output will be a matrix (x1) 
% with each filtered vector as a column in x1.
%
% Note: Matrix inputs will be converted to vector output.

% Written by K. Shein, July 2001

error(nargchk(1, 3, nargin))
if nargin == 1
  x1 = x(~isnan(x)); y1 = [];
else
  if length(x) ~= length(y), 
     error('REMNAN: Vectors must be the same length');
  end;
  if nargin == 3 & length(t) > 1,
      error('REMNAN: t must be a scalar value'); 
  end;
  if nargin == 2, 
      t = 3; 
  end;
  if (t <= 0 | t > 3)
      x1 = x(~isnan(x));
      y1 = y(~isnan(y));
  elseif (t == 1)
      x1 = x(~isnan(x));
      y1 = y(~isnan(x));
  elseif (t == 2)
      x1 = x(~isnan(y));
      y1 = y(~isnan(y));
  elseif (t == 3)
      t1 = find(isnan(x)); % find all NaNs in series x
      t2 = find(isnan(y)); % find all NaNs in series y
      x(t2) = NaN.*ones(size(t2)); % series x with NaNs from series y added.
      y(t1) = NaN.*ones(size(t1)); % series y with NaNs from series x added.
      % Both series should now have corresponding NaN values.
      x1 = x(~isnan(x));
      y1 = y(~isnan(y));
  end;
end;
% if a single output for two input vectors, combine into a matrix
% Column 1 is x1, Column 2 is y1
if nargout == 1 & nargin ~= 1, x1 = [x1(:) y1(:)]; end;

Contact us at files@mathworks.com