You can, actually - however, you have to take into account that in Julia, a
vector and a column matrix are two different things. A vector is a type
that inherently only has one dimension (it is a type-alias for `Array{T,1}`
and a matrix has two dimensions (it's a type-alias for `Array{T,2}`) so
they're fundamentally different.
julia> v = [0
0
1
0
0]
5-element Array{Int64,1}:
0
0
1
0
0
julia> A = zeros(Int,5,1); A[3] = 1; A # There's probably a better way to
do this
5x1 Array{Int64,2}:
0
0
1
0
0
See the type of the outputs? The first one is a "5-element array" while the
second is a "5x1 array". So there really isn't a "second dimension" to get
the size of in the case of a vector. However, you can still do it for the
matrix:
julia> size(v)
(5,)
julia> m, n = size(A)
(5,1)
julia> m
5
julia> n
1
If you initialize A correctly, so that it actually is of a matrix type, you
can use `m, n = size(A)` to get the dimensions into `m` and `n` and it will
work regardless if A has one or more columns.
// Tomas
On Tuesday, April 15, 2014 12:40:14 PM UTC+2, Peter wrote:
>
> Given a vector A defined in Matlab by:
>
> A = [ 0
> 0
> 1
> 0
> 0 ];
>
> we can extract its dimensions using:
>
> size(A);
>
> Apparently, we can achieve the same things in Julia using:
>
> size(A)
>
> Just that in Matlab we are able to extract the dimensions in a vector, by
> using:
>
> [n, m] = size(A);
>
> irrespective to the fact whether A is one or two-dimensional, while in
> Julia A, size (A) will return only one dimension if A has only one
> dimension.
>
> How can I do the same thing as in Matlab in Julia, namely, extracting the
> dimension of A, if A is a vector, in a vector [n m]. Please, take into
> account that the dimensions of A might vary, i.e. it could have sometimes 1
> and sometimes 2 dimensions.
>