Matrix manipulation (matrix A to B format)
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Louis-Philippe Chretien
am 4 Feb. 2019
Kommentiert: Louis-Philippe Chretien
am 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 Kommentare
Adam Danz
am 4 Feb. 2019
Bearbeitet: Adam Danz
am 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)
Akzeptierte Antwort
Andrei Bobrov
am 4 Feb. 2019
Bearbeitet: Andrei Bobrov
am 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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!