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

3 Ansichten (letzte 30 Tage)
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 Kommentare
Joseph Cheng
Joseph Cheng am 24 Jun. 2014
Bearbeitet: Joseph Cheng am 24 Jun. 2014
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 24 Jun. 2014
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 Kommentare
Sandy
Sandy am 24 Jun. 2014
Thanks for pointing it out. I update my question.
Azzi Abdelmalek
Azzi Abdelmalek am 24 Jun. 2014
this is not sufficient as criterion

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by