How to append 3 dimension array( matrix) for example in MATLAB M(:,:,i) = b.
and i don’t know how far ‘i’ will go. so please give solution for initial matrix is blank rather than zeros.
Thank You.
You use the cat
function with the dims
keyword (Arrays · The Julia Language):
C = cat(A, B; dims=3)
1 Like
Another alternative is ElasticArrays.jl. The example in the README is similar to what you describe in your post.
A=rand(1:10, 2,3,2)
B=rand(1:10, 2,3,2)
[A;;;B]
A=rand(1:10, 2,3,2,1)
B=rand(1:10, 2,3,2,2)
[A;;;;B]
To handle concatenation of empty matrices you may need to define a user function. Something like cat2()
below, just to give an idea:
cat2(A,B) = isempty(B) ? A : isempty(A) ? B : [A;;;;B]
I hadn’t paid enough attention to the specific request.
By modifying the @DNF solution in a “dirty” way, maybe you get the desired result (I have not done many tests)
cat(A, B ; dims=1+!isempty(A)*2)