consecutive_runs¶
- consecutive_runs(data, min_len, max_len, value)¶
CONSECUTIVE_RUNS Extract consecutive runs of a specified value from a vector
- Usage:
[run_lengths, run_inds, filtered_vector] = consecutive_runs(data) [run_lengths, run_inds, filtered_vector] = consecutive_runs(data, min_len, max_len, value)
- Inputs:
data : 1xN numeric or logical - input vector – required min_len : double - minimum run length (default: 1) max_len : double - maximum run length (default: inf) value : scalar - value whose runs to extract (default: ones / truthy)
- Outputs:
run_lengths : 1xK double - length of each qualifying run run_inds : 1xK cell - index ranges for each run filtered_vector : logical, same size as data - true at positions inside a run
Notes
Only runs with length in [min_len, max_len] are returned. If value is omitted, runs of ones (or truthy elements) are returned.
Example
lengths = consecutive_runs([1 0 1 1 0 1 1 1 0 0]); % [1 3] [lengths, runs] = consecutive_runs([0 0 1 1 0 1 1 1 0 0 1], 2, 4, 1);
See also: get_chunks, consecutive
∿∿∿ Prerau Laboratory MATLAB Codebase · sleepEEG.org ∿∿∿