Reputation: 111
Let say I have data a= 1x112; my range value is b = [5 30; 35 54; 56 70;78 99]. How can I create zero one value for that range.
I want, the result is a range from 1:4 = 0, 5:30 = 1, 31:34 = 0, 35:54 = 1, 55 = 0, 56:70 = 1, 71:77 = 0, 78:99 = 1.
Anyone please help me. Thank you.
Upvotes: 1
Views: 48
Reputation: 112699
Another possibility: exploiting the order that b
necessarily has,
result = mod(sum(bsxfun(@lt, a, [b(:,1); b(:,2)+1])), 2);
Upvotes: 0
Reputation: 30579
Try bsxfun
, element-wise and
followed by any
:
any(bsxfun(@le,a,b(:,2)) & bsxfun(@ge,a,b(:,1)),1)
Might use a lot of memory if you have big data.
Upvotes: 2