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.softsys.matlab
Notice: We are no longer accepting new posts, but the forums will continue to be readable.
Topic:
Removing rows from a matrix until a condition is met
Replies:
2
Last Post:
Feb 28, 2013 4:38 PM



dpb
Posts:
9,850
Registered:
6/7/07


Re: Removing rows from a matrix until a condition is met
Posted:
Feb 28, 2013 1:41 PM


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




