Eliminating zero's between rising and falling edge
Ältere Kommentare anzeigen
A series with 1's and 0's. a = [0 0 0 1 1 1 0 0 1 1 1 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 ]; and so on... Now I would like to eliminate the zeros in between 1's i.e debouncing and the desired output is: [0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0] . I achieved this using while loop. But if I run the code for about 100 thousand elements the program get's hanged and moreover takes lot of time. For eg: the index for rising edge is 4 and the falling edge is 11, now the zero's between them should be made equal to 1. In the sequence there are atleast 5 or more zeros between the two rising edges.
Would any one suggest the easiest way to solve this?
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 20 Mär. 2014
If you have the Image Processing Toolbox, it's trivial - just a single line of code:
b = ~bwareaopen(~a, 3);
where 3 is the longest length of 0's that you want to allow. 100 thousand elements is no problem - this is just a very small fraction of the number of elements it usually works on (tens of millions of elements or pixels), so it will be pretty fast. If you don't have that toolbox , there are some trickier, more complicated ways to do it. Let us know and someone will probably work it out for you.
1 Kommentar
pr
am 20 Mär. 2014
Kategorien
Mehr zu Image Transforms finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!