You have to think upright. This will allow you to use colon indexing:
>> A(:,:,1) = [1,2,3;2,3,4].'; %'
Two-colon colon indexing works for any dimension A :
>> A(:,:,:,:,1,1) = [1 2 3; 2 3 4].'; %' >> A(:,:,:,:,2,1) = [3 4 5; 4 5 6].'; %' >> A(:,:,:,:,1,2) = [5 6 7; 6 7 8].'; %' >> A(:,:,:,:,2,2) = [7 8 9; 8 9 0].'; %' >> A(:,:) ans = 1 2 3 4 5 6 7 8 2 3 4 5 6 7 8 9 3 4 5 6 7 8 9 0
Indexing columns in MATLAB is quite interesting and really powerful once you get it right. For example, if you use fewer colonies than the sizes in the array (for example, higher), MATLAB automatically merges the rest of the data in size equal to the number of a colon.
So, if A has 48 dimensions, but you index only 2 colons: you get a 2D array, that is, the concatenation of the remaining 46 dimensions in size 2 nd ,
In the general case: if A has dimensions N , but you only index the colon M ≤ N : you get an array M -D, that is, the concatenation of the remaining NM dimensions along size M th .
As long as you are free to define your A to contain vectors in columns rather than rows (you should advise everyone to do this, since almost everything in MATLAB is a little faster) is the fastest and most elegant way to do what you want.
If not, well then just reshape like Dan :)