Matrix manipulation (matrix A to B format)
3 views (last 30 days)
Show older comments
Louis-Philippe Chretien
on 4 Feb 2019
Commented: Louis-Philippe Chretien
on 4 Feb 2019
I need to convert the matrix A (input) to B (output).
matrix A format: (n,2)
eg
A = (a, b; c, d)
matrix B format: (2n, 4)
e.g.
B = (a, b, 1, 0; -b, a, 0,1;c, d, 1,0; -d, c,0,1)
How can I program this so I can convert matrix A with n number of row in order to get matrix B formatting?
Thanks
2 Comments
Adam Danz
on 4 Feb 2019
Edited: Adam Danz
on 4 Feb 2019
If I understand this correctly, matrix A will have n*2 elements and matrix B will have n*2*4 elements. If that's correct, where does the extra data come from to produce matrix B?
Also, in your example below, what is "a" and "b" etc?
B = (a, b, 1, 0; -b, a, 0,1;c, d, 1,0; -d, c,0,1)
Accepted Answer
Andrei Bobrov
on 4 Feb 2019
Edited: Andrei Bobrov
on 4 Feb 2019
AA = [A,repmat([1,0],size(A,1),1)];
A3 = reshape(kron(AA,[1;1]),[],2,2);
A3(2:2:end,:,:) = flip(A3(2:2:end,:,:),2).*[-1,1];
B = reshape(A3,[],4);
More Answers (0)
See Also
Categories
Find more on Data Type Conversion 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!