How can I get the values of two colums in a matrix that are between a given values?

I need to obtain the first two columns in a matrix M that are between two given values (two for each). I have tried this:
find((M(:,1)<V1) & (M(:,1)>V2) & (M(:,2)<V3) & (M(:,2)>V4)
and also
index = M(M(:,1)>V1 & M(:,1)<V2 & M(:,2)>V3 & M(:,2)<V4)
And similar ways that are not giving my expected result. I would like to know an efficient way to do that, since the matrix dimensions are big.
Thank you

2 Comments

what you have there does look like it should work. Can you expand on what you are expecting? What you have there is the index of when both col1 and col2 are between their respective boundaries.
So I was asking wrong, sorry. I need the values on this index. My question is if can I take the result of index = find((M(:,1)<V1) & (M(:,1)>V2) & (M(:,2)<V3) & (M(:,2)>V4) and just make: M(index)? Because it doesn't work as I hope. It gives me just the values on the first column, and I need the second one too. Maybe there's a more appropriate way to do this?
Thank you

Sign in to comment.

 Accepted Answer

ii=M(:,1)<V1 & M(:,1)>V2 & M(:,2)<V3 & M(:,2)>V4
out=find(ii,2)

More Answers (0)

Asked:

on 4 Apr 2014

Commented:

on 4 Apr 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!