You can simplify the declaration as follows:

    MM = Matrix(Matrix(1,2))

You can use comprehensions too:

    MM = [ randn(5,5) for x=1:2, y=1 ]

Here, MM has two rows and one column, and each of its elements is a 5x5
matrix.

-- mb


On Thu, Jun 23, 2016 at 9:28 PM, Sheehan Olver <dlfivefi...@gmail.com>
wrote:

> This caught me by surprise:
>
>
> *julia> **M=rand(5,5)*
>
> *5x5 Array{Float64,2}:*
>
> * 0.621195  0.30108    0.611089  0.880044  0.779199*
>
> * 0.100477  0.0581337  0.198601  0.639252  0.400357*
>
> * 0.716917  0.179181   0.548913  0.787072  0.157769*
>
> * 0.971473  0.981921   0.307854  0.201917  0.290429*
>
> * 0.43822   0.362467   0.160296  0.725931  0.850726*
>
>
> *julia> **Matrix{Float64}[M M]*
>
> *ERROR: MethodError: `convert` has no method matching
> convert(::Type{Array{Float64,2}}, ::Float64)*
>
> *This may have arisen from a call to the constructor
> Array{Float64,2}(...),*
>
> *since type constructors fall back to convert methods.*
>
> Closest candidates are:
>
>   call{T}(::Type{T}, ::Any)
>
>   convert{T,S,N}(::Type{Array{T,N}},
> *::SubArray{S,N,P<:AbstractArray{T,N},I<:Tuple{Vararg{Union{AbstractArray{T,1},Colon,Int64}}},LD}*
> )
>
>   convert{T,n}(::Type{Array{T,n}}, *::Array{T,n}*)
>
>   ...
>
>  in copy! at abstractarray.jl:344
>
>  in typed_hcat at abstractarray.jl:784
>
>
> What's the correct way to do this?  The following works but is not ideal:
>
> *julia> **MM=Matrix{Matrix{Float64}}(1,2)*
>
> *1x2 Array{Array{Float64,2},2}:*
>
> * #undef  #undef*
>
>
> *julia> **MM[1,1]=M;MM[1,2]=M*
>
>
>
>
>

Reply via email to