Sudden changes in data values - how to detect?

I have a matrix of data with around 2000 rows and only 1 column. They first few hundred are all numerical values between 1-10 and then all of a sudden, there is a change in the values to numbers between 1000-10000. How could i write a code to find the position in which this change occurs? I have been stuck with the question for several days and i can't think of a logical way to do it. I am extremely new to matlab.
Thank you

 채택된 답변

Star Strider
Star Strider 2015년 2월 25일

1 개 추천

The easiest way:
x = [randi(10, 20, 1); randi([1000 10000], 20, 1)]; % Created Data
jump = find(diff([0; x]) > 10, 1, 'first'); % Index
The ‘jump’ variable has the first index of the difference in the values that is greater than 10. Run my simulated code — and experiment with it to see how it works — then apply it to your vector.

댓글 수: 4

James Wright
James Wright 2015년 2월 25일
편집: James Wright 2015년 2월 25일
Hello, thank you for your reply, I understand how this works but is there a way to standardise this procedure. For example, if I have some other data that is like in 0.1 and then all of a sudden becomes 0.00001? Is there a way I could write a code which would find a sudden change using any data?
Thank you again
Star Strider
Star Strider 2015년 2월 25일
편집: Star Strider 2015년 2월 25일
My pleasure.
You would have to adjust the threshold and the comparison condition, but the code should work otherwise.
The same code for your new vector might be:
x = [0.1*randi(10, 20, 1); 1E-5*randi(10, 20, 1)]; % Created Data
jump = find(x < 1E-2, 1, 'first'); % Index
Experiment to get the result you need.
RobB
RobB 2015년 6월 8일
This could help me, but is it possible to show the location of multiple changes? Say you had several large jumps in one column of data...is it possible to have matlab tell us more than just the first location? Thanks!
Yes.
See my Comment to dpb’s Answer in your original Question.

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

추가 답변 (1개)

Steven Lord
Steven Lord 2022년 11월 2일

1 개 추천

Since this question was asked the ischange function has been added to MATLAB. Its short description is "Find abrupt changes in data".

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2015년 2월 25일

답변:

2022년 11월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by