Finding change point of an array values

조회 수: 5 (최근 30일)
moncef soualhi
moncef soualhi 2019년 11월 9일
편집: Image Analyst 2019년 11월 10일
Hi every one,
Please, i need help on specified task. I have vectors (as shown in the attached figure) and i would like to extract the points where the vector starts to decrase.
I did not found the appropriate functions to do it.
The data points is also in the attached file
Thank you in advance for your help.
Best regards

채택된 답변

Adam Danz
Adam Danz 2019년 11월 9일
편집: Adam Danz 2019년 11월 10일
There are probably some smart algorithms that will be helpful (Image Analyst mentioned some hints). But here's a lower-level solution that relies on a subjetive threshold such that when the change in y-values drops below the threshold, it triggers the detection.
I only downloaded your figure and extracted the y values from each line and this works with your 3 lines. In this code, y is a vector of y-values from one of your lines.
How it works: It uses a sliding window (currently set to 5 coordinates) and compares the mean of the first 4 values and the last value. If the fraction y(5)/mean(y(1:4)) is less than 0.99, it detects the drop.
%Define window size: number of samples within window
win = 5;
% Sliding window that compares the last value in the window with the
% mean of the preceeding values in the window. If the mean/last is < .99
% it detects the change. Assumes drop is not prior to the index win-1
dropFound = false; % search flag
i = 1; %starting index
while ~dropFound
dropFound = y(i+win-1)/mean(y(i:i+win-2)) < 0.99;
i = i+1;
if i == numel(y)-win
% if you get to the end and haven't found a drop,
% quit the loop and throw a warning
warning('Drop not found')
end
end
yChangeIdx = i+win-2; % Index of coordinate that drops
xline(x(yChangeIdx)) % Draw a vertical line at the drop
  댓글 수: 6
moncef soualhi
moncef soualhi 2019년 11월 10일
it's works verry well. Thank you very much.
Image Analyst
Image Analyst 2019년 11월 10일
편집: Image Analyst 2019년 11월 10일
Glad it's working for you to find only relevant decreasing segments. At first you said decreasing, which means that the next point was lower than the prior point, which is solved a different way.
By the way, including screenshots means using the image icon to insert a PNG file so we can see it immediately in your post. If you attach a fig file, then there is extra work. We have to right click then save it somewhere, then we have to use MATLAB to find the file and open it - that's not as quick and easy.
fileName = 'data_threshold.mat';
s = load('data_threshold.mat')
numArrays = length(s.XTrain)
for k = 1 : numArrays
thisVector = s.XTrain{k};
plot(thisVector, '-', 'LineWidth', 2);
hold on;
end
grid on;
caption = sprintf('%d vectors in %s', numArrays, fileName);
title(caption, 'FontSize', 15, 'Interpreter', 'none');
xlabel('Index', 'FontSize', 15);
ylabel('XTrain', 'FontSize', 15);
0000 Screenshot.png

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2019년 11월 9일
Can you post a screenshot of your plot? In the meantime, check out findchangepts() and diff.
% Find index where vec starts to decrease
d = diff(vec);
index = find(d<0, 1, 'first') + 1;
  댓글 수: 1
moncef soualhi
moncef soualhi 2019년 11월 9일
Thank you for your help, but i'm sorry it does not work in this case, i tried this kind of strategy before.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by