## Find the location of the change

### Tala Hed (view profile)

on 13 Jan 2019
Latest activity Edited by Star Strider

on 25 Jan 2019

### Star Strider (view profile)

Hi :)
I would like to find the location of the change in an array. The arrays are ramp and hold, i e. they contain several identical values then start to increase and then become constant again. The increase rates are different in each array.They are plotted below: I want to plot a vertical line at the end and begining of each constant section. Can you help me with that?
Thanks

### Release

R2018b ### Star Strider (view profile)

on 13 Jan 2019
Edited by Star Strider

### Star Strider (view profile)

on 25 Jan 2019

If you have the Signal Processing Toolbox, consider using the findchangepts (link) function, with the 'Statistic','mean' name-value pair. (The findchangepts function was introduced in R2016a.)
EDIT — (25 Jan 2019 at 20:37 UCT)
Thank you for attaching your data.
The core MATLAB ischange (link) function (introduced in R2017b) turns out to be the best option for this.
The Code —
XX = D.XX;
t = linspace(0, numel(XX), numel(XX));
[TF,SegMean,SegVar] = ischange(XX,'linear','Threshold',500);
cpts = find(TF);
figure
plot(t, XX)
hold on
plot(t(cpts), XX(cpts), '^r', 'MarkerFaceColor','r')
hold off
The Plot —  ### Image Analyst (view profile)

on 13 Jan 2019

Use diff() and line()
Something like (untested)
dy = 0, diff(y)];
% Get non-zero dy
xx = x(mask); % Get x values at those locations.
hold on;
for k = 1 : length(dy)
thisX = xx(k); % Find the x location.
line([thisX, thisX], ylim, 'Color', 'r', 'LineWidth', 2); % Draw a vertical red line.
end

Tala Hed

### Tala Hed (view profile)

on 25 Jan 2019
Thanks a lot. Sorry for my delay. Been out of the country.
The code didnt work. I tried to understand your code and use it, wasent succseful. Here is the vector. Would be grateful if you can help plotting the lines.
Thanks