MATLAB: Determine the start and end of a vector.

decreasesincreasesindexthreshold

When the variable starts incrementing above a threshold, that index is to be determined and also when the same variable starts decrementing below a certain threshold, the index is to be determined.

Best Answer

Try using diff() and strfind():
% Create random sample data.
v = randi(9, 1, 20)
thresh = 3; % Define the threshold.
% Find indexes where v is at or above the threshold.
d = (v>=thresh)
% Find the starting index where the signal starts above the threshold
% and then starts to fall below the threshold.
fallsBelow = strfind(d, [1, 0])
% Find the starting index where the signal starts below the threshold
% and then starts to rise above the threshold.
risesAbove = strfind(d, [0, 1])