MATLAB: Obtaining data from matrix outside multiple ranges

dataindexingmatrixobtainrange

Hi all,
I have a massive matrix, lets call it A:
A=[1 -2 3 4 5 6 7;
3 4 5 6 7 8 9;
4 5 6 6 8 9 10;
4 6 7 8 9 0 12;
2 11 5 7 2 7 21];
and I would like to obtain any row(s), where the 2nd column's data is within these two ranges: 0<A(:,2)<5 and 10<A(:,2)<15.
I know how to do this for one specified range, but not for two different ranges like above.

Best Answer

Use the or operator |:
A = [1 -2 3 4 5 6 7;
3 4 5 6 7 8 9;
4 5 6 6 8 9 10;
4 6 7 8 9 0 12;
2 11 5 7 2 7 21];
%
idx = 0 < A(:,2) < 5;
idy = 10 < A(:,2) < 15;
B = A(idx | idy, :)
giving
B =
1 -2 3 4 5 6 7
3 4 5 6 7 8 9
4 5 6 6 8 9 10
4 6 7 8 9 0 12
2 11 5 7 2 7 21
(All rows of your example matrix fulfill these conditions)