I am trying to concatenate a 2D matrix into a 3D matrix where the length of the 3rd dimension is dependent on length of a vector previously asigned. For example, given
A = [1,2,3,4,5];
B = [1,2;3,4];
I would like creat marix C with size 2x2x5. I can do this easily by doing
However if I change the length of A, I want to write my code so that I don't have to update then number of times "B" repeats itself inside the cat function. I tried using the folowing for-loop but it didn't work. Any advice would be appreciated.
C = cat(3,B,B)