Equivalent to matlab diff(x)

I’m trying to find a function in a package or atleast a way to structure the code in order to to take the difference between each element in an array.

for example
x= (1 1 2 3 5 8 13 21)
Note diff(x) is matlab’s
y = diff(x)

output:
y = (0 1 1 2 3 5 8)

julia> x = [1, 1, 2, 3, 5, 8, 13, 21]
8-element Vector{Int64}:
  1
  1
  2
  3
  5
  8
 13
 21

julia> y = diff(x)
7-element Vector{Int64}:
 0
 1
 1
 2
 3
 5
 8
6 Likes


https://docs.julialang.org/en/v1/base/arrays/#Base.diff

also type ?diff then hit enter in Julia REPL gives you:

help?> diff
search: diff symdiff setdiff symdiff! setdiff! Cptrdiff_t

  diff(A::AbstractVector)
  diff(A::AbstractArray; dims::Integer)
3 Likes

Thank you so much helped a lot!!

1 Like