Matrix manipulation (matrix A to B format)
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Adam Danz
2019-2-4
编辑:Adam Danz
2019-2-4
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)
采纳的回答
Andrei Bobrov
2019-2-4
编辑:Andrei Bobrov
2019-2-4
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!