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
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

댓글을 달려면 로그인하십시오.

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by