consecutive_runs¶
- consecutive_runs(data, min_len, max_len, value)¶
CONSECUTIVE_RUNS Extract consecutive runs of a specified value from a binary vector
- Usage:
[run_lengths, run_inds, filtered_vector] = consecutive_runs(data, min_len, max_len, value)
- Inputs:
data : 1xN double/logical - binary vector – required min_len : integer - minimum run length (default: 1) max_len : integer - maximum run length (default: inf) value : scalar - value to extract runs of (default: extract runs of ones)
- Outputs:
run_lengths : 1xR integer - length of each selected run run_inds : 1xR cell - start/end indices of each selected run filtered_vector : 1xN double - binary vector with ones at kept-run positions
Notes
Runs with length in [min_len, max_len] (inclusive) are returned. If value is omitted, runs of ones are extracted.
Example
lengths = consecutive_runs([1 0 1 1 0 1 1 1 0 0]); % returns [1 3] [lengths, run_inds] = consecutive_runs([0 0 1 1 0 1 1 1 0 0 1], 2, 4, 1); % returns lengths = [2 3] and run_inds = {[3 4], [6 8]}.
See also: get_chunks, find, histcounts
∿∿∿ Prerau Laboratory MATLAB Codebase · sleepEEG.org ∿∿∿