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: efficient find row
Replies: 1   Last Post: Oct 13, 2011 8:03 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Andreas Lobinger

Posts: 12
Registered: 7/29/11
efficient find row
Posted: Oct 13, 2011 7:51 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


i was wandering, if there is an efficient way to find rows equal to a certain vector in matrices.

My current approach (which varies) is something like this
r =

3 1 3
3 2 1
2 2 2
3 2 2

test_vector =
3 2 1
>> find(sum(bsxfun(@eq,test_vector,r),2) == 3)

so built an element specific test for all entries and then sum up the trues and
find within them.

It works and it's OK.

If you need to do this often, you built a lot of values not needed later on ->
the first non-equal already spoils the whole row.

Any idea?
Wishing a happy day,

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.