How to remove a particular value (index) from an array? And also how to add a particular variable to an existing array?
8 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
More Answers (1)
Walter Roberson
on 17 Feb 2017
Edited: Walter Roberson
on 17 Feb 2017
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 Comments
See Also
Categories
Find more on Numeric Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!