필터 지우기
필터 지우기

How to find increasing data points in an array?

조회 수: 6 (최근 30일)
Sujay
Sujay 2022년 12월 7일
편집: Jiri Hajek 2022년 12월 7일
There's an array of random elements A=[2 1 4 2 6 7 8 10 12 14 16 18 20 22 24 12 10 9 11 8 ] now here from n=5 the value sarts increasing till n=15 position. My target is to find this increasing data points in the array and determine their position and remove those data points as well. I have already tried with diff function but I am not getting the results which I want. How can I do it? if someone say it would be of really great help.
  댓글 수: 1
Jiri Hajek
Jiri Hajek 2022년 12월 7일
편집: Jiri Hajek 2022년 12월 7일
Hi, I believe the diff function is a good starting point. The method you need requires to identify clusters of array elements, which you can do using the result of diff. It's not too difficult, but as often, devil is in the detail. If you need to make the method robust and applicable to any vector size, you must start by a precise definition of all possibile scenarios (single largest cluster, several same-size clusters, strictly increasing clusters or non-decreasing clusters etc.).

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

채택된 답변

Walter Roberson
Walter Roberson 2022년 12월 7일
A=[2 1 4 2 6 7 8 10 12 14 16 18 20 22 24 12 10 9 11 8 ]
diffA = diff(A)
start = find(diffA > 0,1);
Now start might be empty (if no elements are increasing anywhere). If it is not empty then it is the first place in the array where you have increasing elements. You can then search diffA starting from start+1 looking for the first place that the difference is <= 0. That first location is where the run of increasing values ends.
Hint: if you find(subset_of_diffA <= 0, 1) where subset_of_diffA is extracted from diffA... and you adjust the output result to take into account that the subset does not start until after start -- and you take into account that the result of that second find() might be empty because there might turn out not to be any places where the results stop increasing...

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by