time | Calls | line |
---|
| | 1 | %MISSING Create a missing value
|
| | 2 | % M = MISSING returns a missing value which can be assigned into an array
|
| | 3 | % to represent missing data. Datatypes that support missing values will
|
| | 4 | % convert M to their native missing value.
|
| | 5 | %
|
| | 6 | % Examples:
|
| | 7 | %
|
| | 8 | % % Denote an element of a double array as missing
|
| | 9 | % a = 1:5
|
| | 10 | % a(2) = missing
|
| | 11 | %
|
| | 12 | % % Denote several elements of a datetime array as missing
|
| | 13 | % d = datetime:(datetime+4)
|
| | 14 | % d([1,3,4]) = missing
|
| | 15 | %
|
| | 16 | % See also ISMISSING, FILLMISSING, ISNAN
|
< 0.001 | 2 | 17 | classdef (Sealed) missing < matlab.mixin.internal.MatrixDisplay
|
| | 18 | methods (Hidden)
|
| | 19 | function disp(m)
|
| | 20 | disp(string(m));
|
| | 21 | end
|
| | 22 |
|
| | 23 | function b = ismissing(m, indicators)
|
| | 24 | if nargin > 1
|
| | 25 | try
|
| | 26 | if isa(m, 'missing')
|
| | 27 | if ~isa(indicators, 'missing')
|
| | 28 | error(message('MATLAB:invalidConversion', 'missing', class(indicators)));
|
| | 29 | end
|
| | 30 | else
|
| | 31 | b = deferCall('ismissing', m, indicators);
|
| | 32 | return;
|
| | 33 | end
|
| | 34 | catch ME
|
| | 35 | throwAsCaller(ME);
|
| | 36 | end
|
| | 37 | end
|
| | 38 | b = true(size(m));
|
| | 39 | end
|
| | 40 |
|
| | 41 | function d = double(m)
|
| | 42 | d = nan(size(m));
|
| | 43 | end
|
| | 44 |
|
| | 45 | function d = single(m)
|
| | 46 | d = nan(size(m), 'single');
|
| | 47 | end
|
| | 48 |
|
| | 49 | function s = string(m)
|
| | 50 | s = string(nan(size(m)));
|
| | 51 | end
|
| | 52 |
|
| | 53 | function s = struct(varargin)
|
| | 54 | if nargin == 1
|
| | 55 | error(message('MATLAB:invalidConversion', 'struct', 'missing'));
|
| | 56 | else
|
| | 57 | try
|
| | 58 | s = builtin('struct', varargin{:});
|
| | 59 | catch e
|
| | 60 | throwAsCaller(e);
|
| | 61 | end
|
| | 62 | end
|
| | 63 | end
|
| | 64 |
|
| | 65 | function o = horzcat(varargin)
|
| | 66 | o = deferCall('horzcat', varargin{:});
|
| | 67 | end
|
| | 68 |
|
| | 69 | function o = vertcat(varargin)
|
| | 70 | o = deferCall('vertcat', varargin{:});
|
| | 71 | end
|
| | 72 |
|
| | 73 | function o = cat(dim, varargin)
|
| | 74 | if ismissing(dim)
|
| | 75 | dim = nan;
|
| | 76 | end
|
| | 77 | varargin = convertCell(varargin);
|
| | 78 | o = redispatch('cat', dim, varargin{:});
|
| | 79 | end
|
| | 80 |
|
| | 81 | function b = isequal(varargin)
|
| | 82 | b = false;
|
| | 83 | end
|
| | 84 |
|
| | 85 | function b = isequaln(varargin)
|
| | 86 | try
|
| | 87 | b = deferCall('isequaln', varargin{:});
|
| | 88 | catch
|
| | 89 | b = false;
|
| | 90 | end
|
| | 91 | end
|
| | 92 |
|
| | 93 | function b = lt(left, right)
|
| | 94 | b = falseExpand(left, right);
|
| | 95 | end
|
| | 96 |
|
| | 97 | function b = le(left, right)
|
| | 98 | b = falseExpand(left, right);
|
| | 99 | end
|
| | 100 |
|
| | 101 | function b = gt(left, right)
|
| | 102 | b = falseExpand(left, right);
|
| | 103 | end
|
| | 104 |
|
| | 105 | function b = ge(left, right)
|
| | 106 | b = falseExpand(left, right);
|
| | 107 | end
|
| | 108 |
|
| | 109 | function b = eq(left, right)
|
| | 110 | b = falseExpand(left, right);
|
| | 111 | end
|
| | 112 |
|
| | 113 | function b = ne(left, right)
|
| | 114 | b = ~falseExpand(left, right);
|
| | 115 | end
|
| | 116 | end
|
| | 117 |
|
| | 118 | methods (Hidden, Access=protected)
|
| | 119 | function displayImpl(m, ~, ~)
|
| | 120 | disp(m);
|
| | 121 | if isscalar(m) && (matlab.internal.display.formatSpacing == "loose")
|
| | 122 | fprintf(newline);
|
| | 123 | end
|
| | 124 | end
|
| | 125 | end
|
| | 126 | end
|
| | 127 |
|
| | 128 | function arg = convertCell(arg)
|
| | 129 | missings = cellfun(@(x)isa(x, 'missing'), arg);
|
| | 130 | found = find(~missings, 1);
|
| | 131 | if ~isempty(found)
|
| | 132 | prototype = arg{found};
|
| | 133 | try
|
| | 134 | arg(missings) = cellfun(@(x)feval(class(prototype), repmat(missing, size(x))), arg(missings), 'UniformOutput', false);
|
| | 135 | catch e
|
| | 136 | e.throwAsCaller;
|
| | 137 | end
|
| | 138 | end
|
| | 139 | end
|
| | 140 |
|
| | 141 | function b = falseExpand(left, right)
|
| | 142 | try
|
| | 143 | convertCell({left, right});
|
| | 144 | b = false(size(left)) | false(size(right));
|
| | 145 | catch e
|
| | 146 | e.throwAsCaller;
|
| | 147 | end
|
| | 148 | end
|
| | 149 |
|
| | 150 | function o = redispatch(fcn, varargin)
|
| | 151 | try
|
| | 152 | if isa(varargin{end}, 'missing')
|
| | 153 | o = builtin(fcn, varargin{:});
|
| | 154 | else
|
| | 155 | o = feval(fcn, varargin{:});
|
| | 156 | end
|
| | 157 | catch e
|
| | 158 | e.throwAsCaller;
|
| | 159 | end
|
| | 160 | end
|
| | 161 |
|
| | 162 | function o = deferCall(fcn, varargin)
|
| | 163 | try
|
| | 164 | varargin = convertCell(varargin);
|
| | 165 | o = redispatch(fcn, varargin{:});
|
| | 166 | catch e
|
| | 167 | e.throwAsCaller;
|
| | 168 | end
|
| | 169 | end
|
| | 170 |
|
| | 171 | % Copyright 2017-2019 The MathWorks, Inc.
|
| | 172 |
|