MATLAB: I have an array which is increasing. At one point it starts to decrease. This trend starts repeating many times in array. How to extract only the decreasing portion from that array

array

I have an array which is increasing. At one point it starts to decrease. This trend starts repeating many times in array. How to extract only the decreasing portions from that array and plot another array values which corresponds to that decreasing portion?

Best Answer

d = diff( YourArray(:).' ); %I assume it is a vector of unknown orientation
goes_down = strfind([0 d>0], [1 0]) + 1;
stops_going_down = strfind([0 d<0], [1 0]);
n_seg = length(goes_down);
segs = cell(1, n_seg);
for K = 1 : n_seg;
segs{K} = YourArray(goes_down(K) : stops_going_down(K));
end