Boundary detection, somewhat like bwperim, but for a binary vector?
Show older comments
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
Matt J
on 24 Jul 2022
Don't use "switch" as the name of your vector. It is a Matlab internal keyword.
Accepted Answer
More Answers (0)
Categories
Find more on Images 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!