Files
2026-09-15 15:24:03 -04:00

36 lines
1.3 KiB
Matlab

function [out, removed] = rmmissing (x, varargin)
%RMMISSING Drop missing values (MATLAB R2016b+).
%
% An owuitools compatibility shim; see contains.m for the policy.
%
% Numeric and logical data only, where "missing" means NaN. MATLAB also
% accepts tables, categoricals, strings and datetimes, where missing
% means something different in each; none of those types exist here, so
% this refuses them rather than inventing an answer. For a vector the
% missing elements go; for a matrix the whole ROW goes, as in MATLAB.
if (nargin < 1)
error ('rmmissing: not enough input arguments');
end
if (~isempty (varargin))
error ('rmmissing: this shim takes only (x) - no dimension or option arguments');
end
if (~isnumeric (x) && ~islogical (x))
error (['rmmissing: this sandbox supports numeric and logical input only, not %s - ' ...
'MATLAB''s table, string and categorical types do not exist here'], class (x));
end
if (isvector (x) || isempty (x))
removed = isnan (double (x(:)));
out = x(~removed);
if (size (x, 1) == 1 && ~isempty (x))
out = reshape (out, 1, []);
end
removed = reshape (removed, size (x));
return;
end
removed = any (isnan (double (x)), 2);
out = x(~removed, :);
end