LOGICALFIND

版本 1.0.0.0 (1.9 KB) 作者: Jos (10584)
Find occurrences of consecutive non-zeros in a vector (v1.0, jan 2014)
312.0 次下载
更新时间 2014/1/30

查看许可证

LOGICALFIND - find occurrences of consecutive non-zeros in a vector

B = LOGICALFIND(V, N) returns the starting indices of any occurrences of N or more consecutive non-zeros in the vector V.
[B, E] = LOGICALFIND(V,N) returns the ending indices as well.
[B, E, CS] = LOGICALFIND(V,N) returns a cell array CS with these occurrences: CS{i} is equal to V(B(i):E(i))

V is (or can be converted to) a binary (logical) vector. N is a scalar integer larger than 0.

Example:
V = logical([0 1 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 1])
B = logicalfind(V,3)
% -> B = [8 15]

X = floor(4*rand(20,1)) % a numerical row vector
[B, E, CS] = logicalfind(X,2)
L = E - B + 1 % length of each occurence
isequal(L, cellfun(@numel,CS)) % check!

See also: find, strfind, regexp

引用格式

Jos (10584) (2025). LOGICALFIND (https://ww2.mathworks.cn/matlabcentral/fileexchange/45305-logicalfind), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2011a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0