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?

 채택된 답변

the cyclist
the cyclist 2020년 11월 21일
편집: the cyclist 2020년 11월 21일

0 개 추천

Here is one way:
G = reshape([FF; MF; FM; MM],2,2,6)

댓글 수: 3

Ranny Meier
Ranny Meier 2020년 11월 22일
편집: Ranny Meier 2020년 11월 22일
Thank you. Maybe we were close. Need each page arranged as:
G(:,:,1) =
1.0000 + 2.0000i 7.0000 + 2.0000i
13.0000 + 2.0000i 19.0000 + 2.0000i
R = reshape([FF; MF; FM; MM],2,2,6)
R(:,:,1) =
1.0000 + 2.0000i 7.0000 + 2.0000i
13.0000 + 2.0000i 19.0000 + 2.0000i
At first I missed the added semi-colons in your answer. Now I see that it works.
Also your earlier suggestion that we found in the email is arranged as desired.
H = permute(reshape([FF; FM; MF; MM],2,2,6),[2 1 3 4 5 6])
H(:,:,1) =
1.0000 + 2.0000i 7.0000 + 2.0000i
13.0000 + 2.0000i 19.0000 + 2.0000i
I am reading permute description and have yet to see the magic of how a size 1x6 dimorder works on a size 2x2x6 array.
I postsed that first solution too fast, which is part of the reason I edited it quickly.
The first solution, which I edited away, should only have been:
H = permute(reshape([FF; FM; MF; MM],2,2,6),[2 1 3])
The other dimensions were stupidity, not magic. :-)
Then I realized that if I swapped FM and MF, then the permutation can be avoided, for a much cleaner solution.
Ranny Meier
Ranny Meier 2020년 11월 22일
Definitely not stupid - simply work in progress. Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2020년 11월 21일

댓글:

2020년 11월 22일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by