How can I get the values of two colums in a matrix that are between a given values?
1 view (last 30 days)
Show older comments
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
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.
Accepted Answer
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
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!