Create A Matrix in Julia

to continue this work,

Qw= Matrix{Float64}
push!(Qw[1,:,:] = CCP[1,:,:])

bugs: ERROR: syntax: invalid keyword argument name “Qw[1, :, :]”:sweat_smile: @DNF

julia> Qw= Matrix{Float64}[]
0-element Array{Array{Float64,2},1}

julia> CPP = rand(10,11,12);

julia> push!(Qw, CPP[1,:,:]);

julia> push!(Qw, CPP[2,:,:]);

julia> Qw
2-element Array{Array{Float64,2},1}:
 [0.8935129125586814 0.3470142023127345 … 0.6738768695996915 0.6978520270709654; 0.7923192642936225 0.5547389053048148 … 0.5429744453836987 0.18337287076378694; … ; 0.4865432758891508 0.6267145315230598 … 0.532536699235963 0.7892874407659456; 0.9178282233333892 0.4930127685342016 … 0.6960617819744821 0.046685022605916116]  
 [0.4223869684524322 0.0010646995727199293 … 0.786847325799438 0.21655039764113293; 0.9000478496995337 0.8557975654465664 … 0.7634421366413904 0.7131702618107101; … ; 0.1365000421261684 0.7040795888558846 … 0.805473769012456 0.7592440782847643; 0.6405347764075793 0.11758801287203435 … 0.9800419560473239 0.43556322515432666]
1 Like

Qw is a vector (of matrices), so you cannot index it like this Qw[1,:,:], it only takes a single index. Even if it did work, it would create a copy which you would then push! to, and which then would disappear. Finally, the assignment operator = has no place here.

You can read about how to use push! by typing ?push! in the REPL. @Elrod’s example shows correct usage.