LOGICALEXPAND

expand (or shrink) series in a logical vector (v2.0, feb 2014)

262 Downloads

Updated 3 Mar 2014

View License

Y = LOGICALEXPAND(X,N) returns a logical vector Y of the same length as the vector X.
For N > 0, series of true entries in X are expanded with N values on either side. For N < 0, series of true entries in X are shrinked with N values on either side. For N = 0, Y equals logical(X).

Examples:
% expand by 1
logicalexpand(logical([0 0 0 1 0 0 0 1 1 0 0 0 1]), 1)
% -> [0 0 1 1 1 0 1 1 1 1 0 1 1]

% shrink with 2
logicalexpand(logical([0 1 1 1 1 1 1 0 0 0 1 1 1 1 1]).', -2)
% -> [0 0 0 1 1 0 0 0 0 0 0 0 1 0 0].'

See also find, logicalfind (File Exchange)

Cite As

Jos (10584) (2023). LOGICALEXPAND (https://www.mathworks.com/matlabcentral/fileexchange/45728-logicalexpand), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2011a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.0