Find a specific set of values in a matrix

5 views (last 30 days)
sajad shiekh
sajad shiekh on 13 Mar 2020
Commented: Mohammad Sami on 13 Mar 2020
I'm trying to find some specific values from an array which has two columns
for example if one column looks like [0.1,0.2,0.5,0.6,0.1,0.9,0.1,0.3,0.2,0.5,0.1] I want the numbers >=0.2 from this column and with corresponding number in second column of the array.

Answers (1)

Mohammad Sami
Mohammad Sami on 13 Mar 2020
You can do this quite easily
twocolmat = rand(100,2);
idx = twocolmat(:,1) >= 0.2;
col2vals = twocolmat(idx,2);
  2 Comments
sajad shiekh
sajad shiekh on 13 Mar 2020
This looks fine but I need to do some computation with the corresponding values of another column. As in above example I want numbers in batches such as (0.2,0.5,0.6) a one and second (0.9), 3rd one (0.3,0.2,0.5).....with their correspondind idx
Mohammad Sami
Mohammad Sami on 13 Mar 2020
If you are new to matlab, please go through the matlab onramp course.
It explains how indexing works in matlab among other things.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!