Finding specific number of characters in vector
2 次查看(过去 30 天)
显示 更早的评论
I have a character vector ( c = ['a' 'r' 'y' 'z' 'b' 'u' 'k'] ) and I would to determine the number of characters that are not b or r. How do I do this using logical operators?
1 个评论
Stephen23
2020-9-15
编辑:Stephen23
2020-9-15
Note that
c = ['a' 'r' 'y' 'z' 'b' 'u' 'k'];
is just a more complex and less efficient way of writing
c = 'aryzbuk';
You do not need to concatenate individual characters to make a character vector. It is totally superfluous. No experienced user would bother doing this.
回答(2 个)
Ameer Hamza
2020-9-15
Try setdiff()
c = ['a' 'r' 'y' 'z' 'b' 'u' 'k'];
n = numel(setdiff(c, ['b' 'r']));
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!