For consistency with "nan", wouldn't it be nice to be able to issue "missing(3)"?

1 次查看(过去 30 天)
<Missing> is the string counterpart to NaN. One can define a (say) 3x3 array of NaN's. Each NaN can be replaced as the data is generated in the analysis process, which is handy if the data isn't generated simultaneously. At no point is there any confusion between NaN versus a valid zero datum.
It would be nice to be able to do this for strings. Of course, one can issue "string(nan(3))" or "repmat(missing,3,3)". But as code gets more intricate, simplicity becomes more valuable.
  11 个评论
FM
FM 2022-4-27
@Jan: In 2019a, missing(2,3) and missing(2,3,'string') are not recognized. I'm still waiting to upgrade. The command "doc missing" yields a very sparse documentation page....
Jan
Jan 2022-4-27
@FM: In R2022a this syntax is not working also - you can try this here in the forum's interpreter:
missing(2,3,'string')
Error using missing
Too many input arguments.
So this is a useful enhancement request. Please use the link on the bottom of this page to contact the MathWorks team and suggest this improvement.

请先登录,再进行评论。

回答(1 个)

Bruno Luong
Bruno Luong 2022-4-27
Why not define your own function
mymissing
ans = missing
<missing>
mymissing(3)
ans = 3×3 missing array
<missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing> <missing>
mymissing(2,3)
ans = 2×3 missing array
<missing> <missing> <missing> <missing> <missing> <missing>
mymissing(2,'string')
ans = 2×2 string array
<missing> <missing> <missing> <missing>
mymissing(2,3,'double')
ans = 2×3
NaN NaN NaN NaN NaN NaN
function x = mymissing(varargin)
% x = mymissing(size)
% x = mymissing(n1, n2, ...)
% x = mymissing(..., class)
x = missing;
if ~isempty(varargin)
if ischar(varargin{end}) || isstring(varargin{end})
sz = [varargin{1:end-1}];
if isempty(sz)
sz = 1;
end
cls = varargin{end};
x = repmat(feval(cls,x), sz);
else
sz = [varargin{1:end}];
x = repmat(x, sz);
end
end
end
  12 个评论
FM
FM 2022-4-27
@Bruno Luong: No, I should have been clearer. the 2019a documentation for "missing" does not describe it a specific to "string". I got that from the page cited in my last reply. Which is a very specific page for strings and missing values.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Identification 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by