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

1 view (last 30 days)
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
Joseph Cheng
Joseph Cheng on 4 Apr 2014
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.
Xavier
Xavier on 4 Apr 2014
Edited: Xavier on 4 Apr 2014
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

Azzi Abdelmalek
Azzi Abdelmalek on 4 Apr 2014
Edited: Azzi Abdelmalek on 4 Apr 2014
ii=M(:,1)<V1 & M(:,1)>V2 & M(:,2)<V3 & M(:,2)>V4
out=find(ii,2)
  3 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!