# MATLAB, Removing Certain Elements From An Array That Fits The Condition [closed]

removing elements from an array that have difference of 3 or less between the next element... eg. A=[3 6 10 14 17 20] to this B=[3 10 14 20]...I believe I can use diff but in what context should I use it to achieve this ?

• That's a general Matlab programming question, not a signal processing question, and is thus off-topic here. – Marcus Müller Nov 23 '16 at 14:48

## 1 Answer

This code removes all elements that have diff 3 or less to the previous element.

in = [3 6 10 14 17 20 24 25 30 34 38]
in1 = in(2:end);
D = diff(in)
out = [in(1) in1(D > 3)]


output:

in =

3     6    10    14    17    20    24    25    30    34    38

D =

3     4     4     3     3     4     1     5     4     4

out =

3    10    14    24    30    34    38