If you do size(A,k), it will return 1 for dimensions past the number of
dimensions of A:
julia> A = randn(10)
10-element Array{Float64,1}:
-0.817094
-1.30042
1.04264
-0.537116
0.634901
1.52307
-0.295063
-1.15746
0.233317
0.0574608
julia> size(A)
(10,)
julia> size(A,1)
10
julia> size(A,2)
1
Instead of writing
m, n = size(A)
you can do
m, n = size(A,1), size(A,2)
Another option is to use dispatch to handle the different dimensionalities
separately.
On Tue, Apr 15, 2014 at 7:38 AM, Peter <[email protected]> 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.
>