In MATLAB, the following syntax can be used to create 1-d matrix a
and 2-d matrix b
:
a = [2,3]
b = [2,3;4,5]
In Julia, constructing the 1-d array a
using the same syntax works. However, constructing the 2-d array b
using the same syntax fails.
Defining b
as follows works:
b = cat(2,[2,4],[3,5])
Is there a syntactical shortcut for explicitly defining 2-d arrays in Julia? If so, what is it?
You're likely looking for this:
a = [2,3]
b = [2 3;4 5]
Here's the relevant paragraph from the "Major Differences From MATLAB" section of the Julia docs:
Concatenating scalars and arrays with the syntax
[x,y,z]
concatenates in the first dimension (“vertically”). For the second dimension (“horizontally”), use spaces as in[x y z]
. To construct block matrices (concatenating in the first two dimensions), the syntax[a b; c d]
is used to avoid confusion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With