How to assemble 3D array from four vectors
Show older comments
We have four vectors of complex numbers.
FF = 1 x N vector, FM = 1 x N vector, MF = 1 x N vector, MM = 1 x N vector
We need a 3D array G = 2 x 2 x N array, and where each page is [FF(n) FM(n); MF(n) MM(n)]
FF = [1+2i 2+2i 3+2i 4+2i 5+2i 6+2i];
FM = [7+2i 8+2i 9+2i 10+2i 11+2i 12+2i];
MF = [13+2i 14+2i 15+2i 16+2i 17+2i 18+2i];
MM = [19+2i 20+2i 21+2i 22+2i 23+2i 24+2i];
G = [FF(1) FM(1); MF(1) MM(1)];
for n = 2:6
G(:,:,n) = [FF(n) FM(n); MF(n) MM(n)];
end
G
We tried to assemble it with a reshape function after taking noncongugate transpose.
R = reshape([FF.' MF.'; FM.' MM.'].',2,2,[])
The result is the correct shape of 3D array, and yet it seems that the elements are mixed up.
Is there a better way to assemble this 3D array, other than adding a page at a time in a loop?
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!