How to use 'OR' within a 'CONTAINS' statement for a table?

20 views (last 30 days)
Hi
Within the 2019b release of Matlab, how do I call in an 'OR' statement within a 'CONTAINS' statement with my data in a table?
Example:
HEARD (table column 1): 'the soft cushion broke the mans fall'
TARGET1 (table column 2); 'soft'
TARGET2 (table column 3): 'cushion'
TARGET3 (table column 4): 'broke'
TARGET4 (table column 5): 'man''s'
TARGET5 (table column 6): 'fall'
ALT1 (table column 7): 'mans'
I want Matlab to determine if the HEARD statement contains either TARGET4 or ALT1, and to return 1 for true
I have tried:
W4 = contains(Table{1,1},or(Table{1,5},Table{1,7}));
....and I have tried:
W4 = contains(Table{1,1},Table{1,5}|Table{1,7});
....and :
W4 = contains(Table{1,1},Table{1,5}||Table{1,7});
...but either I get an error message saying that '|' is an undefined operator for input arguments of type 'cell' or that the conversion to logical from cell is not possible.
Can anyone shed any light therefore on how to use contains( or ) with tables? Thanks.

Accepted Answer

Matt J
Matt J on 28 Sep 2019
Edited: Matt J on 28 Sep 2019
W4 = contains(Table{1,1},Table{1,4}) | contains(Table{1,1},Table{1,7})
or
W4 = contains( Table{1,1} , Table{1,[4,7]} )
  2 Comments
Matt J
Matt J on 28 Sep 2019
Philippa Demorte's comment moved here:
Thanks, Matt J! Have tried the second version and it works.
Matt J
Matt J on 28 Sep 2019
You're welcome, but please Accept-click the answer to signify that you found a solution.

Sign in to comment.

More Answers (0)

Categories

Find more on Java Package Integration in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!