Created
March 31, 2012 21:30
-
-
Save ferryzhou/2268713 to your computer and use it in GitHub Desktop.
Get segments from a binary vector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function segs = get_segments(o) | |
segs = []; | |
if o(1), st = 1; state = 1; | |
else state = 2; end | |
for i = 2 : length(o) | |
if o(i) | |
if state == 2 | |
st = i; state = 1; | |
end | |
else | |
if state == 1 | |
ed = i - 1; state = 2; | |
segs = [segs; [st ed]]; | |
end | |
end | |
end | |
if state == 1 | |
segs = [segs; [st i]]; | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment