MATLAB Answers

Using ismember on vector with strings

3 views (last 30 days)
Muazma Ali
Muazma Ali on 3 Oct 2019
Commented: Muazma Ali on 4 Oct 2019
Hi,
I am wonderinh whether I can write something like this:
If any(ismember(result , [" nafor", "kform", "acet"]))

  0 Comments

Sign in to comment.

Accepted Answer

meghannmarie
meghannmarie on 3 Oct 2019
Edited: meghannmarie on 3 Oct 2019
if you are trying to match string to string, try this:
if any(contains([' nafor','kform','acet'],result))

  5 Comments

Show 2 older comments
Muazma Ali
Muazma Ali on 3 Oct 2019
Thanks I understand it now.
Stephen Cobeldick
Stephen Cobeldick on 4 Oct 2019
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?
Muazma Ali
Muazma Ali on 4 Oct 2019
No i was thinking of character vectors and I got my answer yesterday that I accepted :)

Sign in to comment.

More Answers (0)

Sign in to answer this question.