-
Notifications
You must be signed in to change notification settings - Fork 5
/
vremnan.m
45 lines (41 loc) · 1.14 KB
/
vremnan.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function [x] = vremnan(x, dim)
%VREMNAN Removes rows or columns containing NaN.
%
% input
% x = matrix to process
% dim = dimension along which vectors are listed
%
% dim = 1 removes column vectors
% dim = 2 removes row vectors
%
% output
% x = processed input
%
% See also isnan, any.
%
% File: vremnan.m
% Author: Ioannis Filippidis, [email protected]
% Date: 2012.05.11
% Language: MATLAB R2012a
% Purpose: trim columns which contain at least one NaN element
% Copyright: Ioannis Filippidis, 2012-
% DIM
szx = size(x);
if nargin == 1 || isempty(dim)
dim = 1;
% First non singleton dimension
%dim = find(szx ~= 1, 1, 'first');
elseif ~(isnumeric(dim) && (dim > 0) && (rem(dim, 1) == 0) ) || (dim > numel(szx) )
error('vremnan:fmtDim', 'DIM should be a scalar positive integer <= ndims(x)');
end
bad_elements = isnan(x);
bad_columns = any(bad_elements, dim);
bad_columns = ~bad_columns;
switch dim
case 1
x = x(:, bad_columns);
case 2
x = x(bad_columns, :);
otherwise
error('vremnan:dim', 'Dim > 2 is not implemented.')
end