check if values are in multiple ranges

hello, so i have a vector of values a = [1,2,4,5,6]; and I want to know if these are within multiple ragnes. Thus I have a baseline for each range val_bottom = [0, 5, 3, 2]; and i have a ceiling for each vals_top = [5, 10, 8, 12]; . I want to know which of the values in a fall into each range, thus I would like four outputs one for each range. If anyone can help that would be amazing.

 Accepted Answer

>> a = [1,2,4,5,6];
>> val_bottom = [0,5,3,2];
>> vals_top = [5,10,8,12];
>> a(:)>=val_bottom & a(:)<=vals_top
ans =
1 0 0 0
1 0 0 1
1 0 1 1
1 1 1 1
0 1 1 1

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!