I have an array which can be any size (in rows) but is always two columns wide. I would like to throw away any rows containing numbers which stray more than 1 from the median of each column.
For example:
array =
2 5
3 4
9 5
2 8
3 5
. .
. .
. .
etc
In the above example, median(array) gives [2 5]. So, for the columns above, I would expect the third and fourth rows to be eliminated, since row three contains 9 in the first column, and row four contains 8 in the second column, both of which are outside of my limit (1 away from the median). Note that I want to throw away BOTH columns if EITHER column contains a number which is not within 1 of the median for that column.
Any help would be greatly appreciated…
I don’t have MATLAB right now, but I think this should work. You should be able to at least follow the logic.
What the above code is doing is finding all indices where array value in both columns is at most distance 1 from median of each column. Then it selects only those rows that corresponds to these indices.