Prev: moment invariants
Next: Problem with Genetic Algorithm
From: Elizabeth on 31 Mar 2010 09:40 If I have a matrix x: x=[1 2 3;4 5 6;7 8 9;10 11 12]; and i wanted to delete rows 1 and 2 then i can do ab=[1,2]; x[ab,:]=[]; and rows 1 and 2 would be deleted. But what if I wanted to delete all rows EXCEPT 1 and 2. This is a simplified example, as what I actually have is x with a length of over a thousand rows, but I want to delete all but 60 or so of them, but the principle is still the same. thanks
From: us on 31 Mar 2010 09:49 "Elizabeth " <elizabeth.robertson(a)eee.strath.ac.uk> wrote in message <hovjc6$oqn$1(a)fred.mathworks.com>... > If I have a matrix x: > x=[1 2 3;4 5 6;7 8 9;10 11 12]; > > and i wanted to delete rows 1 and 2 then i can do > ab=[1,2]; > x[ab,:]=[]; > > and rows 1 and 2 would be deleted. > But what if I wanted to delete all rows EXCEPT 1 and 2. > > This is a simplified example, as what I actually have is x with a length of over a thousand rows, but I want to delete all but 60 or so of them, but the principle is still the same. > > thanks one of the solutions m=magic(4); kx=[2,4]; m=m(kx,:) % <- just KEEP those, rather then REMOVE them... %{ % m = 5 11 10 8 4 14 15 1 %} us
From: ImageAnalyst on 31 Mar 2010 09:50 How about this: x = [1 2 3;4 5 6;7 8 9;10 11 12] keeperRows = [1,2] allRows = 1:size(x,1) rowsToDelete = setxor(keeperRows, allRows) x(rowsToDelete,:)=[] You could cram it all into a single line if you wanted to be compact (and a bit harder to understand) instead of verbose/descriptive.
|
Pages: 1 Prev: moment invariants Next: Problem with Genetic Algorithm |