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 ]
dpb

Posts: 8,183
Registered: 6/7/07
Re: Extracting particular row of a matrix based on specific condition
Posted: Dec 30, 2013 9:30 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 12/29/2013 3:25 PM, Poulomi wrote:

...Don't toppost -- hard conversation follow makes...

> dpb <none@non.net> wrote in message <l9q2j3$pa8$1@speranza.aioe.org>...
>> On 12/29/2013 2:39 PM, Poulomi wrote:
>> > "Poulomi" wrote in message <l9q0oj$7ef$1@newscl01ah.mathworks.com>...
>> ...
>> >> ...A = [519 520 521 1000]
>> ...
>> >> B = [1000 0.12 0.005 0.1
>> >> 520 0.13 0.001 0.89
>> >> 518 0.12 0.002 0.98
>> >> 600 0.14 0.004 0.90];
>> >>
>> >> I need to pick up the values in A matrix, find out common 1st column
>> >> element in Matrix B and extract corresponding row. Say, 520, 1000 is
>> >> common in both matrix, so my output will be a new matrix C = [0.12
>> >> 0.005 0.1
>> >> 0.13 0.001 0.89];
>> >>
>> >> Let me know how to do so. Thanks,

>> >
>> > Sorry my output C will be in same order as the elements in A matrix, so
>> > C = [0.13 0.001 0.89
>> > 0.12 0.005 0.1]. Please let me know. Thanks,

>>
>> C=B(ismember(B(:,1),A'),2:end);


> Thanks, but I need the order to be maintained same as A matrix, so that
> C = [0.13 0.001 0.89
> 0.12 0.005 0.1].


In that is mandatory either reorder or use accumarray() or a loop to
process in that order.

--




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.