How can I detect number that does not follow an increasing order?

조회 수: 3 (최근 30일)
Sandy
Sandy 2014년 6월 24일
편집: Joseph Cheng 2014년 6월 24일
I have a vector like this:
  • 1 2 3 4 100 5 6 7
or it could also be like this:
  • 153 158 161 163 172 123 179 181
if I look at the vector, I know I should delete 100 in 1st one and 123 in 2nd one. After that, either vector is in an increasing order.
I tried to use code diff(vector) to solve the problem in Matlab.
For 1st vector, the difference: 1 1 1 96 -95 1 1. The negative appears at 5th and I should delete No.5 in original sample.
For 2nd vector, the difference: 5 3 2 9 -49 56 2. The negative appears at 5th but I should delete No.6 in original sample.
The code diff cannot handle both cases at the same time. I am wondering if there is a more effective way.
Thank you very much!
  댓글 수: 5
Joseph Cheng
Joseph Cheng 2014년 6월 24일
편집: Joseph Cheng 2014년 6월 24일
perhaps some peak detection. performing the convolution of the pattern will lineup max of the convolution with the point that you want to take out. (works with b as well) [a;0 conv(a,[-.5 1 -.5],'valid') 0]
1.0000 2.0000 3.0000 4.0000 100.0000 5.0000 6.0000 7.0000
0 0 0 47.5000 95.5000 48.0000 0 0
and for b
153.0000 158.0000 161.0000 163.0000 172.0000 123.0000 179.0000 181.0000
0 1.0000 0.5000 3.5000 29.0000 52.5000 27.0000 0
might not work for all cases, more sophisticated methods for finding local maximum and local minimum may be what you are looking for.

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 6월 24일
s=[153 158 161 163 172 123 179 181 4 5 190]
while any(diff(s)<0)
ii=[1==0 diff(s)<0]
s(ii)=[];
end
  댓글 수: 4
Sandy
Sandy 2014년 6월 24일
Thanks for pointing it out. I update my question.
Azzi Abdelmalek
Azzi Abdelmalek 2014년 6월 24일
this is not sufficient as criterion

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by