Searching a Table for rows that meet specific criteria

I have a table that has length in column1 and mass in column2. i want to search this table for every row where column1 is between 0.35 and 0.32, and where column 2 is less than 1.3. but im unsure of how to do this. any help is appreciated.

 Accepted Answer

You can use logical indexing. You can use multiple conditional expressions to create your logical index. The result is an array the length of your conditional data. A 1 means the condition(s) were met, and 0 means they were not. Use that to index the original array.
A=rand(5,2)
A = 5×2
0.8273 0.8719 0.0490 0.9542 0.0813 0.2350 0.7649 0.1481 0.7011 0.7902
ind = A(:,1)>.5 & A(:,2)<.5;
A(ind,:)
ans = 1×2
0.7649 0.1481

1 Comment

thanks! been stuck for ages i'm new to matlab and enjoying learning it!

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

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

Start Hunting!