How to use logical "OR" operation for comparing string??
13 次查看(过去 30 天)
显示 更早的评论
I tried with the code as given:
strcmp('normal'||'neptune',{'normal'; 'DoS'; 'neptune'; 'R2L'})
and the error is saying that the OR "||" operator must be convertible to logical scalar values. So, what could be the possible solution to this?? thanks in advance.
0 个评论
采纳的回答
Walter Roberson
2017-12-15
any( ismember({'normal', 'neptune'}, {'normal'; 'DoS'; 'neptune'; 'R2L'}) )
4 个评论
Walter Roberson
2017-12-15
For the index positions,
[tf, idx] = ismember({'normal', 'neptune'}, {'normal'; 'DoS'; 'neptune'; 'R2L'})
The returned idx would be [1 3] in this example.
idx(K) will be valid only in the locations where tf(K) is true (and will be 0 otherwise.)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!