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: Removing rows from a matrix until a condition is met
Replies: 2   Last Post: Feb 28, 2013 4:38 PM

Advanced Search

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

Posts: 8,106
Registered: 6/7/07
Re: Removing rows from a matrix until a condition is met
Posted: Feb 28, 2013 1:41 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 2/28/2013 11:26 AM, Dave Williams wrote:
> I want to remove rows from a matrix until a certain condition is met. I
> want to do this from both the top and the bottom of the matrix....
>
> i.e.
>
> 3 4 8 3
> 4 6 9 4
> 4 0 7 4
> 2 1 6 5
> 6 0 9 3
> 7 0 8 2
> 4 2 5 1
>
> I want the matrix restricted so that column 2 is always 0 in the first
> and last rows. The size of the matrix will vary. In this case the result
> would be:
>
> 4 0 7 4
> 2 1 6 5
> 6 0 9 3
> 7 0 8 2
>
> So the first two rows and the last row are removed


"Straightahead" solution--

>> ix=~all(x,2);
>> i1=find(ix,1,'first');i2=find(ix,1,'last');
>> ix(i1:i2)=true;
>> y=x(ix,:)

y =
4 0 7 4
2 1 6 5
6 0 9 3
7 0 8 2
>>

--



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.