how to add empty in double array xxx = [ NaN 2 3 4 NaN]....Expected Value [ '' 2 3 4 '' ]

11 ビュー (過去 30 日間)
deepika Sridhar
deepika Sridhar 2021 年 12 月 23 日
コメント済み: Voss 2021 年 12 月 23 日
xxx=[nan 2 3 4 NaN]
xxx =
NaN 2 3 4 NaN
K>> class(xxx)
ans =
'double'

回答 (1 件)

Rik
Rik 2021 年 12 月 23 日
That is not possible. You will either have to use a cell array, or remove the values entirely.
{'',2,3,4,''}
ans = 1×5 cell array
{0×0 char} {[2]} {[3]} {[4]} {0×0 char}
[2,3,4]
ans = 1×3
2 3 4
  1 件のコメント
Voss
Voss 2021 年 12 月 23 日
To add on to this answer, here is how you might convert xxx to a cell array and replace the NaNs with '':
xxx = [NaN 2 3 4 NaN];
nan_idx = isnan(xxx);
xxx = num2cell(xxx);
xxx(nan_idx) = {''};
display(xxx);
xxx = 1×5 cell array
{0×0 char} {[2]} {[3]} {[4]} {0×0 char}

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by