Matrix manipulation (matrix A to B format)

7 visualizaciones (últimos 30 días)
Louis-Philippe Chretien
Louis-Philippe Chretien el 4 de Feb. de 2019
Comentada: Louis-Philippe Chretien el 4 de Feb. de 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 comentarios
Adam Danz
Adam Danz el 4 de Feb. de 2019
Editada: Adam Danz el 4 de Feb. de 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)
Louis-Philippe Chretien
Louis-Philippe Chretien el 4 de Feb. de 2019
What I'm trying to do is to convert for example a set of coordinates (X, Y) into another coordinate system. So in matrix A (n rows, 2 columns), I have for each row a set of X and Y coordinates. I can have 2 and more row of coordinates to convert.
In matrix B (2n rows, 4 columns), the coordinate stay the same but I need to change the formatting of matrix A in order to apply the transformation coefficient matrix (matrix C: 4 rows,1 column). I also need to add 1 and 0 in the third and fourth column for the necessity of the calculation.

Iniciar sesión para comentar.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 4 de Feb. de 2019
Editada: Andrei Bobrov el 4 de Feb. de 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);

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by