How to make a NaN vector if there is a single NaN in a column?

1 次查看(过去 30 天)
Say you have a vector
A= [ 2 4 6 8 NaN 10 12 14]
How do you make a NaN vector if and only if there is a NaN in one of the columnns:
A = [NaN NaN NaN NaN NaN... ]

采纳的回答

madhan ravi
madhan ravi 2020-7-28
[m, n] = size(A);
A = nan(m, any(isnan(A(:))) * n)
  8 个评论
Cnell
Cnell 2020-7-28
I thought the "if and only if" gave that away. Perhaps I should have been more clear, my apologies.
madhan ravi
madhan ravi 2020-7-28
Sorry I’m not a mind reader:(
ix = nan(m, any(isnan(A(:)))* n);
if isempty(ix)
A = A
else
A = ix
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by