Home > utils > find_turnarounds.m

find_turnarounds

PURPOSE ^

[turn_idxs] = find_turnarounds(traj);

SYNOPSIS ^

function [turn_idxs, turn_vals] = find_turnarounds(cvals)

DESCRIPTION ^

 [turn_idxs] = find_turnarounds(traj);

 Finds direction reversals in the input vector, and returns the indices of the
 reversals.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [turn_idxs, turn_vals] = find_turnarounds(cvals)
0002 % [turn_idxs] = find_turnarounds(traj);
0003 %
0004 % Finds direction reversals in the input vector, and returns the indices of the
0005 % reversals.
0006 %
0007 
0008 % 07/27/05 Petr Janata
0009 
0010 cidxs = 1:length(cvals);
0011 
0012 % Go ahead and get the turn arounds.  These occur whenever
0013 % the direction of the bin values changes sign
0014 cdir = diff(cvals);
0015 
0016 % Remove repeated values
0017 rep_idxs = find(~cdir);
0018 cdir(rep_idxs) = [];
0019 cidxs(rep_idxs+1) = [];
0020 
0021 % Get the pure direction -- irrespective of jump size
0022 dirvect = sign(cdir);
0023 
0024 % Get indices that consistute turnarounds
0025 turn_idxs = cidxs(find([0; diff(dirvect)])+1)-1;
0026 turn_vals = cvals(turn_idxs);
0027 
0028 return

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003