Migrating code from Matlab or Octave to Julia - gher-uliege/Documentation GitHub Wiki
Syntax changes
- place strings in double quotes:
'hello'
->"hello"
- indexes uses square brackets
- functions always end with
end
- beware Julia does much less copies than Matlab/Octave (e.g. during assignmement, reshape, ...)
a = [1,2,3]
b = a
b[1] = 0
# a[1] is now 0 too!
-
[1:3]
is valid but it is an array of a range (Array{UnitRange{Int64},1}
) in Julia. If you want an array of number from 1 to 3, use[1:3;]
(returning an array) or1:3
(returning a range). -
operator precedence is different. In matlab
true & 3 < 2
is evaluated astrue & (3 < 2)
and is thusfalse
, while in Julia (version 0.5.0),true & 3 < 2
is evaluated as(true & 3) < 2
and istrue
(sincetrue & 3
is 1). Here is more information about operator precedence in julia and matlab. In Julia,true && 3 < 2
returnsfalse
, as expected.
Interpolation
mif = interpn(x,y,m,Xi,Yi);
itp = interpolate((x,y), Int.(mask),Gridded(Linear()))
mif = itp[Xi[:,1],Yi[1,:]];
Other
- use
NullableArray
instead of NaN for missing values (https://github.com/JuliaStats/NullableArrays.jl) - print -> saveas
- remove "shading flat"
- function calls: clf -> clf()
See also http://docs.julialang.org/en/stable/manual/noteworthy-differences/.