How to append 3 dimension array( matrix) for example in MATLAB M(:,:,i) = 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)