The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: find all numbers in a vector
Replies: 4   Last Post: Dec 3, 2012 10:24 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Roger Stafford

Posts: 5,929
Registered: 12/7/04
Re: find all numbers in a vector
Posted: Dec 3, 2012 10:00 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Petra" wrote in message <k9jerd$h6o$>...
> a=[2 3 14 15 16 17 18 33 34 35]
> b=[17 18 35 60 61 62]
> and I try to find all numbers and position in a which are in b.
> The answer should be: 6 7 8 10

"Petra" wrote in message <k9jmf4$boc$>...
> you are right
- - - - - - - - - -
You shouldn't give up so quickly, Petra. The answer you gave was correct - for the positions in 'a'.

Use both returned quantities in the function 'ismember' to determine both the numbers in 'a' which are also in 'b' and their positions. Bear in mind of course that in case there is more than one like number in 'a' which is duplicated in 'b', you will get the position of the one with highest index.

Roger Stafford

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.