MATLAB: Find a position of last changing value in array

function

Hello,
i'm looking for function that detect a position of detection of last changing value (value stay constant or have just little changes).
In this case tube_dimension = 37;
I'm realize this in for-loop, but maybe thereare better way?
Sensivity_old = Sensivity;
TP ...
FN ....
Sensivity = (TP ./ (TP + FN));
if (Sensivity > Sensivity_old + 1.0e-03)
Sencivity_end = tube_cnt;
else
end
disp(Sencivity_end)
Thank you!

Best Answer

Hi Nikita,
You can use MATLAB's built in function differentrial (diff) to find out the minimum variability points of your data. The first index of the those points would be where your data would have the plateau. If you can attach some data, I would give you a code as well, otherwise psuedo code is:
plateau_points=diff(sensitivity);
plateau_points=find(plateau_points ==0) % finding where the points have 0 change
plateau_tube_dimension=tube_dimension(plateau_points(1));
Hope this helps,
Thanks!