Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


dpb
Posts:
9,218
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 >>




