finding number sequences in a vector and set them to the adjacent values
4 views (last 30 days)
Show older comments
Ronny Guendel
on 17 Jun 2019
Commented: Ronny Guendel
on 19 Jun 2019
Hello,
I have a vector, which represents basically a binary signal [0,1].
if the consecutive binary numbers is smaller than x, I want to find them and set them to the opposite value.
Example:
binaryValue = [ 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0];
if I define:
x <=4 ; % for zero values;
i will have:
binaryValue_new = [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0];
0 Comments
Accepted Answer
Stephen23
on 17 Jun 2019
>> V = [ 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0]
V =
0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
>> D = diff([0,V,0]);
>> B = find(D>0);
>> E = find(D<0)-1;
>> X = 4;
>> for k = 1:numel(B), if (E(k)-B(k))<X, V(B(k):E(k)) = 0; end, end
>> V
V =
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
More Answers (0)
See Also
Categories
Find more on Logical 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!