Julia for MATLAB Users/Core Language/Language Fundamentals
Language Fundamentals[edit | edit source]
This page maps MATLAB functionality documented in the Language Fundamentals section of the MATLAB documentation to equivalent Julia (core language and/or package) functionality.
Another helpful resource is the noteworthy differences from MATLAB section of the Julia documentation.
Entering Commands[edit | edit source]
Related: Julia REPL
ans
Most recent answer[edit | edit source]
Julia's ans
is functionally basically identical, though note that it is available only at the REPL.
clc
Clear Command Window[edit | edit source]
Ctrl+L is nearly equivalent in the Julia REPL, though it does not erase history; you can still scroll up to see the history of the session. You can also equivalently (on Linux/Mac) run the clear(1)
command in shell mode, i.e. ;+clear.
save
Command Window text to file[edit | edit source]
There doesn't appear to be an equivalent Julia REPL command.
format
Set Command Window output display format[edit | edit source]
There is no drop-in equivalent in the Julia REPL or IJulia for globally setting the output format.
home
Send cursor home[edit | edit source]
Ctrl+L is functionally equivalent in the Julia REPL.
iskeyword
Determine whether input is MATLAB keyword[edit | edit source]
There doesn't appear to be an equivalent Julia command, but see Keywords in the Julia manual.
more
Control paged output for Command Window[edit | edit source]
Matrices and Arrays[edit | edit source]
See Multi-dimensional Arrays in the Julia Manual.
zeros
Create array of all zeros; ones
Create array of all ones[edit | edit source]
Julia's zeros
and ones
are functionally equivalent. Note that the syntax for specifying the data type of the result is different, e.g. Julia: zeros(Int64, 3, 3)
vs. MATLAB zeros(3,3, 'int64')
.
rand
Uniformly distributed random numbers[edit | edit source]
See Julia's rand
.
true
Logical 1 (true); false
Logical 0 (false)[edit | edit source]
eye
Identity matrix[edit | edit source]
In Julia to construct a numeric identity matrix, use something like Matrix(1.0I, 3, 3)
. Note that the symbol I
is special in Julia; rather than representing a matrix, it is an instance of the UniformScaling
operator so that in principle its use can be more efficient than the naive use of a dense matrix that happens to have 1's on the diagonal and zeros elsewhere.
diag
Create diagonal matrix or get diagonal elements of matrix[edit | edit source]
blkdiag
Construct block diagonal matrix from input arguments[edit | edit source]
cat
Concatenate arrays along specified dimension[edit | edit source]
horzcat
Concatenate arrays horizontally[edit | edit source]
See Julia's hcat function
vertcat
Concatenate arrays vertically[edit | edit source]
repelem
Repeat copies of array elements[edit | edit source]
repmat
Repeat copies of array[edit | edit source]
linspace
Generate linearly spaced vector[edit | edit source]
logspace
Generate logarithmically spaced vector[edit | edit source]
freqspace
Frequency spacing for frequency response[edit | edit source]
meshgrid
2-D and 3-D grids[edit | edit source]
ndgrid
Rectangular grid in N-D space[edit | edit source]
length
Length of largest array dimension[edit | edit source]
Julia has a length
function, however it does not operate the same way as Matlab's for multidimensional arrays. To get equivalent behavior to Matlab's length(X)
, use maximum(size(X))
in Julia.
size
Array size[edit | edit source]
ndims
Number of array dimensions[edit | edit source]
In Julia, ndims
is similar but not identical. For instance, Julia does not ignore singleton dimensions.
numel
Number of array elements[edit | edit source]
In Julia, length
is equivalent.
isscalar
Determine whether input is scalar[edit | edit source]
isvector
Determine whether input is vector[edit | edit source]
ismatrix
Determine whether input is matrix[edit | edit source]
isrow
Determine whether input is row vector[edit | edit source]
iscolumn
Determine whether input is column vector[edit | edit source]
isempty
Determine whether array is empty[edit | edit source]
sort
Sort array elements[edit | edit source]
sortrows
Sort rows of matrix or table[edit | edit source]
issorted
Determine if array is sorted[edit | edit source]
issortedrows
Determine if matrix or table rows are sorted[edit | edit source]
topkrows
Top rows in sorted order[edit | edit source]
flip
Flip order of elements[edit | edit source]
fliplr
Flip array left to right[edit | edit source]
flipud
Flip array up to down[edit | edit source]
rot90
Rotate array 90 degrees[edit | edit source]
transpose
Transpose vector or matrix[edit | edit source]
ctranspose
Complex conjugate transpose[edit | edit source]
permute
Rearrange dimensions of N-D array[edit | edit source]
ipermute
Inverse permute dimensions of N-D array[edit | edit source]
circshift
Shift array circularly[edit | edit source]
shiftdim
Shift dimensions[edit | edit source]
reshape
Reshape array[edit | edit source]
squeeze
Remove singleton dimensions[edit | edit source]
Julia's dropdims
function is similar though it requires the singleton dimension(s) to be specified explicitly.
colon
Vector creation, array subscripting, and for-loop iteration[edit | edit source]
end
Terminate block of code, or indicate last array index[edit | edit source]
Julia's end
is basically equivalent.
ind2sub
Subscripts from linear index[edit | edit source]
sub2ind
Convert subscripts to linear indices[edit | edit source]
Operators and Elementary Operations[edit | edit source]
See Mathematical Operations and Elementary Functions in the Julia manual.
Arithmetic[edit | edit source]
plus
Addition[edit | edit source]
uplus
Unary plus[edit | edit source]
minus
Subtraction[edit | edit source]
uminus
Unary minus[edit | edit source]
times
Element-wise multiplication[edit | edit source]
rdivide
Right array division[edit | edit source]
ldivide
Left array division[edit | edit source]
power
Element-wise power[edit | edit source]
mtimes
Matrix Multiplication[edit | edit source]
mrdivide
Solve systems of linear equations xA = B for x[edit | edit source]
mldivide
Solve systems of linear equations Ax = B for x[edit | edit source]
mpower
Matrix power[edit | edit source]
cumprod
Cumulative product[edit | edit source]
cumsum
Cumulative sum[edit | edit source]
diff
Differences and Approximate Derivatives[edit | edit source]
movsum
Moving sum[edit | edit source]
prod
Product of array elements[edit | edit source]
sum
Sum of array elements[edit | edit source]
ceil
Round toward positive infinity[edit | edit source]
fix
Round toward zero[edit | edit source]
floor
Round toward negative infinity[edit | edit source]
idivide
Integer division with rounding option[edit | edit source]
mod
Remainder after division (modulo operation)[edit | edit source]
rem
Remainder after division[edit | edit source]
round
Round to nearest decimal or integer[edit | edit source]
bsxfun
Apply element-wise operation to two arrays with implicit expansion enabled[edit | edit source]
Relational Operations[edit | edit source]
eq
Determine equality[edit | edit source]
ge
Determine greater than or equal to[edit | edit source]
gt
Determine greater than[edit | edit source]
le
Determine less than or equal to[edit | edit source]
lt
Determine less than[edit | edit source]
ne
Determine inequality[edit | edit source]
isequal
Determine array equality[edit | edit source]
isequaln
Determine array equality, treating NaN values as equal[edit | edit source]
Logical Operations[edit | edit source]
Logical Operators: Short-circuit Logical operations with short-circuiting[edit | edit source]
and
Find logical AND[edit | edit source]
not
Find logical NOT[edit | edit source]
or
Find logical OR[edit | edit source]
xor
Find logical exclusive-OR[edit | edit source]
all
Determine if all array elements are nonzero or true[edit | edit source]
any
Determine if any array elements are nonzero[edit | edit source]
false
Logical 0 (false)[edit | edit source]
find
Find indices and values of nonzero elements[edit | edit source]
In Julia, findall
provides similar functionality. See also findfirst
, findlast
, findnext
and findprev
.
islogical
Determine if input is logical array[edit | edit source]
logical
Convert numeric values to logicals[edit | edit source]
true
Logical 1 (true)[edit | edit source]
Set Operations[edit | edit source]
intersect
Set intersection of two arrays[edit | edit source]
ismember
Array elements that are members of set array[edit | edit source]
ismembertol
Members of set within tolerance[edit | edit source]
issorted
Determine if array is sorted[edit | edit source]
setdiff
Set difference of two arrays[edit | edit source]
setxor
Set exclusive OR of two arrays[edit | edit source]
union
Set union of two arrays[edit | edit source]
unique
Unique values in array[edit | edit source]
uniquetol
Unique values within tolerance[edit | edit source]
join
Combine two tables or timetables by rows using key variables[edit | edit source]
innerjoin
Inner join between two tables or timetables[edit | edit source]
outerjoin
Outer join between two tables or timetables[edit | edit source]
Bit-Wise Operations[edit | edit source]
bitand
Bit-wise AND[edit | edit source]
bitcmp
Bit-wise complement[edit | edit source]
bitget
Get bit at specified position[edit | edit source]
bitor
Bit-wise OR[edit | edit source]
bitset
Set bit at specific location[edit | edit source]
bitshift
Shift bits specified number of places[edit | edit source]
bitxor
Bit-wise XOR[edit | edit source]
swapbytes
Swap byte ordering[edit | edit source]
Data Types[edit | edit source]
See Types in the Julia manual.