필터 지우기
필터 지우기

Detecting a Continuing Increase/Decrease, or Stabilizing Trend in Data

조회 수: 75 (최근 30일)
Yuntian Guan
Yuntian Guan 2016년 6월 27일
답변: Superficial 2020년 3월 12일
Hi,
Jumping into the question: so I have some data in somewhat like this:
A = [1 2 1 2 1 2 3 4 5 6 7];
basically it will start to increase at some point, and I'd like to know where that 'some point' is. For the example above, is there a code/function that lets MatLab detect the increase in consecutively 3 numbers (6th element) and return the position?
The final purpose is to delete the parts before the consecutive increase and keep the parts after it; for now I'd really like to understand that part;
Thanks in advance,
  댓글 수: 1
Image Analyst
Image Analyst 2016년 6월 28일
The signal starts increasing, with a run of 3 or more, at element #5, with the number 1. Why did you say it starts at element number 6?

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

답변 (3개)

Image Analyst
Image Analyst 2016년 6월 28일
This code is fairly robust. It finds all runs where it's monotonically increasing for 3 elements or more and prints out information about that run. It can handle more than one run, or no runs at all, and gets info on all existing runs.
A = [1 2 1 2 1 2 3 4 5 6 7 5 8 0 1 3 6 9 4];
da = diff(A)>0
stats = regionprops(bwlabel(da), 'Area', 'PixelIdxList')
% Find which runs have a length of at least
% 3 elements of monotonically increasing elements
threeOrLonger = find([stats.Area] >= 3)
% Print out those sequences.
if ~isempty(threeOrLonger)
for blobIndex = 1 : length(threeOrLonger)
% This blob is 3. Find where the blob starts and stops.
startingIndex = stats(threeOrLonger(blobIndex)).PixelIdxList(1);
endingIndex = stats(threeOrLonger(blobIndex)).PixelIdxList(end)+1;
% Print out that run.
fprintf('For run #%d, startingIndex = %d, endingIndex = %d, the elements = ', ...
blobIndex, startingIndex, endingIndex);
fprintf('%d', A(startingIndex : endingIndex));
fprintf('\n');
end
else
msgbox('No run is 3 or longer');
end

Superficial
Superficial 2020년 3월 12일
I know I'm late to this thread, but this is my solution to this problem. Perhaps not as elegant but easy to understand.
I wanted to determine the value (in y) and timepoint (in x) of the start of a reaction.
for i=2:length(y)-1 % Exclude first and last values in series so y(i-1) and y(i+1) actually do exist
if y(i-1)<y(i) && y(i)<y(i+1) % finds 3 consecutive rising values
break
end % Ends the 'if' statement at this point.
end
% i is therefore the index of the (middle of 3) rising values in y
risevalue=y(i)
% In my case I wanted the x value as well to define the x (time) value at the same point
timepoint=x(i);

KSSV
KSSV 2016년 6월 28일
You can calculate diff of diff of A, when it remains constant, form that position the function increases. Eg:
A = [1 2 1 2 1 2 3 4 5 6 7];
K = diff(diff(A)) ;
idx = find(K==0) ;
iwant = idx(1)+1
Also go through monotonically increasing functions and monotonically decreasing functions.
Eg.
x = [1 2 3 4 5 6]
all(diff(x)>0) % increasing
% But now:
x(7) = 3
all(diff(x)>0)

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by