From: ruben.uma Rios on 30 May 2010 11:38 Hello, I would like to know if there's a simple and efficient way to detect rows in a matrix with any of its values outside a range of values, so that I can delete that row. For instance: A = [ 1 5 6 0 12 3] If the range is x > 0 & x < 10, I would like to delete A(2,:) and A(3,:) Is there a function that might help me to detect the rows?
From: ImageAnalyst on 30 May 2010 12:50 A = [ 1 5; 6 0; 12 3] logicalArray = ~(A > 0 & A < 10) rowsToKeep = sum(logicalArray, 2) == 0 newA = A(rowsToKeep,:) A = 1 5 6 0 12 3 logicalArray = 0 0 0 1 1 0 rowsToKeep = 1 0 0 newA = 1 5
From: Walter Roberson on 30 May 2010 12:52 ruben.uma Rios wrote: > I would like to know if there's a simple and efficient way to detect > rows in a matrix with any of its values outside a range of values, so > that I can delete that row. For instance: > > A = [ 1 5 > 6 0 > 12 3] > > If the range is x > 0 & x < 10, I would like to delete A(2,:) and A(3,:) > > Is there a function that might help me to detect the rows? You want to detect rows, but you want to delete columns?? any(A <= 0 | A >= 10,2) will return a column vectors of logical values that tell you whether anything in the corresponding row was out of range.
From: ruben.uma Rios on 30 May 2010 13:32 Thank you very much, that seems to be an easy way of doing it. I was hoping a magical one-function solution, but your solution is good enough :-) All the best! ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <ba93a24a-8d15-43b5-b488-77c8432809c5(a)g39g2000pri.googlegroups.com>... > A = [ 1 5; 6 0; 12 3] > logicalArray = ~(A > 0 & A < 10) > rowsToKeep = sum(logicalArray, 2) == 0 > newA = A(rowsToKeep,:) > > A = > > 1 5 > 6 0 > 12 3 > > > logicalArray = > > 0 0 > 0 1 > 1 0 > > > rowsToKeep = > > 1 > 0 > 0 > > > newA = > > 1 5
From: ImageAnalyst on 30 May 2010 15:57 You could combine all that into a single line but in the interests of readability and maintainability I'd advise against it. When someone comes along later and needs to figure out what's happening, it can be tough to figure out what these cryptic "one liner" statements are doing.
|
Next
|
Last
Pages: 1 2 Prev: Matrix superposition Next: help spline toolbox, multiple end conditions |