1

I have a list of strings that I am looking for in a pdb

X1 = ['N' 'CA' 'CB' 'CG1']%Isoleucine

I want to compare these strings to the atoms as so:

atoms = find(strcmp({pdb.Model.Atom(:).resName}, 'ILE') & ...
               (strcmp({pdb.Model.Atom(:).AtomName}, 'N') |...
                strcmp({pdb.Model.Atom(:).AtomName}, 'CA') | ...
                strcmp({pdb.Model.Atom(:).AtomName}, 'CB') | ...
                strcmp({pdb.Model.Atom(:).AtomName}, 'CG1')))

Is there a more concise way to do this? Also is there a way for strcmp to do an exact match? not just if it contains the string?

EDIT:

A more concrete example:

I want to be able to do this:

strcmp(['hello' 'world'], ['hello' 'world' 'this' 'is' 'a' 'test'])

and it returns whether it matched with hello or world. This instead returns a zero saying that it can't find this array ['hello' 'world'] in ['hello' 'world' 'this' 'is' 'a' 'test'].

Essentially I just want to know if 'hello' and 'world' are in the larger array instead of checking if it contains both 'hello' and 'world' in the same row

3
  • @Sardar_Usama I have added a more concrete example Commented Nov 11, 2016 at 19:50
  • Note that ['hello' 'world'] is not a list of strings in MATLAB: it's a single string 'helloworld'. Commented Nov 11, 2016 at 19:59
  • @AndrasDeak Thanks! I did not realize this! Commented Nov 11, 2016 at 20:00

1 Answer 1

5

The first half of your question makes me uncertain, but the second formulation is easily answerable:

>> ismember({'hello' 'world'}, {'hello' 'world' 'this' 'is' 'a' 'test'})

ans =

     1     1

As you can see, ismember works for cell arrays (which is the general container for strings). So you can probably use all to check the presence of each of the strings in the larger collection:

all(ismember({pdb.Model.Atom(:).AtomName},{'N','CA','CB','CG1'}))
Sign up to request clarification or add additional context in comments.

1 Comment

And may I also suggest the use of upper to convert all your AtomNames to uppercase before you do the comparison for the rainy day when Ca Cb creep into the AtomName

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.