MATLAB Answers


Using ismember on vector with strings

Asked by Muazma Ali on 3 Oct 2019
Latest activity Commented on by Muazma Ali on 4 Oct 2019
I am wonderinh whether I can write something like this:
If any(ismember(result , [" nafor", "kform", "acet"]))


Sign in to comment.

1 Answer

Answer by meghannmarie on 3 Oct 2019
Edited by meghannmarie on 3 Oct 2019
 Accepted Answer

if you are trying to match string to string, try this:
if any(contains([' nafor','kform','acet'],result))


Thanks I understand it now.
Note that [] is a concatenation operator, so this code:
[' nafor','kform','acet']
is just a complex way of writing this:
' naforkformacet'
Perhaps you actually intended to define strings, rather than character vectors?
No i was thinking of character vectors and I got my answer yesterday that I accepted :)

Sign in to comment.