translation

Chapter 38 of the Julia Language Documentation

https://en.wikibooks.org/wiki/Julia_for_MATLAB_Users

R uses the `{}`

to denote a block of statements. Julia uses the `end`

keyword to terminate blocks.

Julia doesn't allow the `<-`

, `<<-`

and `->`

operators that are used commonly in R code.

Most julia objects are assigned by reference, i.e., an assignment creates an alias not a copy.

- R :
`c(1,2,3)`

- Julia :
`[1,2,3]`

Vectors are always typed and flattened in R, but not in julia.

- R :
`A %*% B`

- Julia :
`A * B`

Julia and Matlab have very similar syntax, with a few notable differences. This file should help you convert Matlab code into Julia.

The list of registered Julia packages can be found at the Pkg list website, or at Julia.jl.

Some common matlab libraries and their equivalents include:

- Bioinformatics Toolbox → Bio.jl
- Statistics and Machine Learning Toolbox → StatsBase.jl, MLBase.jl

Also, Julia uses the `import`

, `using`

and `include`

constructs to import code from other files or packages.

Matlab and Julia use very similar notations for vector indexing, and differ only in the operator used: Matlab uses the `A(1,2)`

notation, while Julia uses the `A[1,2]`

notation.

Most julia objects are assigned by reference, i.e., an assignment creates an alias not a copy.

The square root of an `-1`

is denoted by the symbol `im`

in Julia. Complex numbers in general are represented by the `Complex{T}`

type. The complex form of a number can be obtained using the `complex`

function.

In Julia file names aren't associated with the functions they contain. A file may contain multiple modules and functions and can be named arbitrarily.

Matlab uses named output arguments. Julia uses explicit return statements. The syntax for declaring anonymous functions also differs in Julia.

- snippet.juliarepl
julia> function f

**(**x**,**y**)**; return**(**x + y**)**; end#function julia> f=**(**x**,**y**)**->**(**x + y**)**julia> f**(**x**,**y**)**=**(**x + y**)**

In Julia, array indices begin with 1. In Perl, array indexes begin with 0.

In Python indentations are used to identify statement blocks. In Julia, the keyword `end`

is often used to terminate a block of statements.

- snippet.julia
function f

**(**x**,**y**)**x**,**y end

- snippet.python
[download only julia statements] def f(x,y): return(x,y)

In Julia, array indices begin with 1. In Python, array indexes begin with 0.

- snippet.juliarepl
julia> A =

**[**1**,**2**,**3**]**julia> A**[**0**]**ERROR: BoundsError: attempt to access 3-element Array**{**Int64**,**1**}**at index**[**0**]**

- Common Gotchas.
- Opinionated relative language advantages and disadvantages

In Julia, methods do not belong to objects, but are implementations of generic functions. If you're used to Object oriented languages such as Python, this may seem strange. In python you'd use the `.`

operator to access an objects methods. In Julia, you would pass the object as the first argument to the function. For example, to define a Class `Person`

with an age accessor method in Python, you would do:

- snippet.python
[download only julia statements] class Person: def __init__(self, age): self.age = age def get_age(self): return(self.age) p = Person(10) python> p.get_age()

- snippet.juliarepl
julia> type Person age::Int end##type## julia> getAge

**(**x::Person**)**= x.age julia> p = Person**(**10**)**julia> getAge**(**p**)**10

translation.txt · Last modified: 2018/08/25 08:24 (external edit)