How to remove a particular value (index) from an array? And also how to add a particular variable to an existing array?
8 ビュー (過去 30 日間)
古いコメントを表示
hs(n) = {1,2,3,4} if i want to remove '3' from hs(n). What should i do? if i want to add '5' to hs(n). What should i do? Please use some variables to answer this ... Thanks in advance :)
0 件のコメント
採用された回答
その他の回答 (1 件)
Walter Roberson
2017 年 2 月 17 日
編集済み: Walter Roberson
2017 年 2 月 17 日
mask = ismember(hs(n), 'a');
hs{n}(mask) = [] ;
Note that the order of arguments for the ismember for this purpose is the opposite of what you might expect.
Also this code expects a cell array of strings, consistent with your use of '3' but not consistent with your initial assignment which had a cell array of numeric values. You used the string form more so I programmed for that.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Numeric Types についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!