Search All of the Math Forum:

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

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

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

 Messages: [ Previous | Next ]
 dpb Posts: 9,850 Registered: 6/7/07
Re: Extracting particular row of a matrix based on specific condition
Posted: Dec 31, 2013 9:48 AM

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...

The previously-posted solution which OP doesn't like of

B(ismember(B(:,1),A),2:end)

gets the right rows but they're in order returned from A which isn't
same order as in B.

A one-liner hasn't occurred to me on this one, yet anyway...best I've
gotten is two--

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

ans =
0.1300 0.0010 0.8900
0.1200 0.0050 0.1000
>>

'cuz need the second output from ismember() instead of the first to get
the position vector instead of logical with which to rearrange the
output order.

--

Date Subject Author
12/29/13 Pg
12/29/13 Pg
12/29/13 dpb
12/29/13 Pg
12/30/13 dpb
12/31/13 Bruno Luong
12/31/13 dpb
1/1/14 Bruno Luong
1/2/14 dpb
1/2/14 Pg
1/2/14 dpb
1/3/14 dpb
1/2/14 Bruno Luong
1/2/14 dpb
1/3/14 dpb