Boundary detection, somewhat like bwperim, but for a binary vector?

Hi everyone,
I have a binary vector with lots of sequences, e.g.:
switch = [0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0]
The length of this vector is some total number of timesteps T.
I want to plot boxes along a figure's x-axis which show whether switch is on (1) or off (0).
To do that, I need the (x-axis) limits or boundaries of the boxes.
Is there a quick way to obtain boundaries for a binary vector?
I have tried using bwperim but I think it is designed for 2D images primarily and does not do what I'm looking for.
(If I run bwperim(switch), I just receive switch right back.)
In the case of switch, the boundaries would be [1, 3], [4, 7], [8, 11], [12, 14], [15, 15].
Any help would be much appreciated! Thank you so much.

1 Comment

Don't use "switch" as the name of your vector. It is a Matlab internal keyword.

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Asked:

on 24 Jul 2022

Commented:

on 24 Jul 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!