How to filter out single/double zero's ?
Ältere Kommentare anzeigen
A = [1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0]
I have vector A and I want to smoothen the vector by changing the single 0's or double 0's to 1's. This means that I want to keep the consecutive zero's when bigger than 2 consecutive.
Is there an easy way to do this without using a for loop?
Thanks
Akzeptierte Antwort
Weitere Antworten (2)
B=char([1 A 1]+'0');
B=strrep(B, '101','111');
B=strrep(B,'1001','1111');
B=B(2:end-1)-'0';
Guillaume
am 23 Sep. 2019
If you have the Image Processing Toolbox, the easiest is:
newA = imclose(A, [1 1 1])
Kategorien
Mehr zu Robotics System Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!