get_chunks

get_chunks(data, min_len, max_len)

GET_CHUNKS Extract consecutive runs of equal values from a vector

Usage:

[run_lengths, run_inds, run_values, filtered_vector] = get_chunks(data, min_len, max_len)

Inputs:

data : 1xN vector - input data – required min_len : integer - minimum run length (default: 1) max_len : integer - maximum run length (default: inf)

Outputs:

run_lengths : 1xR integer - length of each selected run run_inds : 1xR cell - start/end indices of each selected run run_values : 1xR - value of each run filtered_vector : 1xN double - binary vector with ones at kept-run positions

Example

x = [2 2 5 5 5 6 6 6 6 4 7 2 2 2]; [lengths, runs] = get_chunks(x, 2, 4); % lengths = [2 3 4 3], runs = {[1 2],[3 4 5],[6 7 8 9],[12 13 14]}

See also: consecutive_runs

∿∿∿ Prerau Laboratory MATLAB Codebase · sleepEEG.org ∿∿∿