a = [1,2,3,4,5,6,7,8,9];R = a(3:end)-a(1:end-2)
R =
2 2 2 2 2 2 2
注意matlab的数组索引方法,参考代码:
a = 1:9;b = a(3:5) - a(1:3)