Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

Topic: Extracting particular row of a matrix based on specific condition
Replies: 14   Last Post: Jan 3, 2014 10:03 AM

Advanced Search

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

Posts: 128
Registered: 1/24/09
Re: Extracting particular row of a matrix based on specific condition
Posted: Jan 2, 2014 11:12 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

dpb <none@non.net> wrote in message <la3v66$3rm$1@speranza.aioe.org>...
> On 1/1/2014 3:50 AM, Bruno Luong wrote:
> > dpb <none@non.net> wrote in message <l9ulhp$sf7$1@speranza.aioe.org>...
> >> On 12/31/2013 2:16 AM, Bruno Luong wrote:
> >> > B(ismember(A,B(:,1)),2:end)
> >>
> >> That returns the rows in B for which the indices are found in A, not
> >> B, unfortunately, Bruno. It does get the first one correct as they're
> >> both in position 2, but then it returns fourth row, not first where
> >> the last element of A is found in first column of B...

> >
> > You are write, it learns me not to do things too fast.
> >

> >>
> >> >> [~,lb]=ismember(A,B(:,1));
> >> >> B(lb(lb>0),2:end)

> >> ans =
> >> 0.1300 0.0010 0.8900
> >> 0.1200 0.0050 0.1000

> >> >>
> >>
> >
> > Should use the first argument of ismember() rather than recomputing it.
> > Also OP requires the original order, so sort() will fix the order:
> >
> > [t, iB] = ismember(A,B(:,1));
> > B(sort(iB(i)),2:end)

>
> Been puzzling over your last comment, Bruno...couldn't decide what you
> meant by "recomputing it". I guess you're speaking of the logical test
> to select nonzero elements instead of just a direct use of the logical
> addressing vector.
>
> The problem I see with sort() is that I think in the general case the
> results could be jumbled since the two matrices are given independently.
> AFAICT there's no guarantee the magnitude order would be the same as
> the position order in the B array of an arbitrary selection of values in
> the A vector. Or, at least, that's my understanding of the OP's quest...
>
> --

sort is not working but indexing one is working fine. I checked with random element, my matrix size is 3822x14.



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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.