I want to extract specific data from a matrix and organize in another matrix
24 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Daniel
el 17 de Oct. de 2022
Comentada: Daniel
el 17 de Oct. de 2022
Hi-
I have a 3x3 matrix A=[1 2 3; 5 7 9; 4 6 8] and want to use the digits to extract data from the row and column they represent in another 9x9 matrix B=[0 2 4 3 2 4 5 2 7; 2 0 4 3 2 4 5 2 7; 3 4 0 9 8 7 4 3 2; 9 4 3 0 2 3 9 8 7; 3 2 1 9 0 9 3 2 4; 9 4 5 6 3 0 9 3 2; 3 2 4 5 6 7 0 3 9; 4 3 2 5 7 6 4 0 9; 4 3 4 5 4 3 2 5 0] and place the answer in matrix C. C should be equal to [B(1,2) B(1,3) B(2,3); B(5,7) B(5,9) B(7,9); B(4,6) B(4,8) B(6,8)]. I hope this makes sence. It should walk the A matrix finding every interaction for the row and col coordinates to extract from B. Thanks!
0 comentarios
Respuesta aceptada
Image Analyst
el 17 de Oct. de 2022
Try this:
A=[1 2 3; 5 7 9; 4 6 8]
% and want to use the digits to extract data from the row and column they represent
% in another 9x9 matrix
B=[0 2 4 3 2 4 5 2 7; 2 0 4 3 2 4 5 2 7; 3 4 0 9 8 7 4 3 2; 9 4 3 0 2 3 9 8 7; 3 2 1 9 0 9 3 2 4; 9 4 5 6 3 0 9 3 2; 3 2 4 5 6 7 0 3 9; 4 3 2 5 7 6 4 0 9; 4 3 4 5 4 3 2 5 0]
% and place the answer in matrix C.
% C should be equal to [B(1,2) B(1,3) B(2,3);
% B(5,7) B(5,9) B(7,9);
% B(4,6) B(4,8) B(6,8)].
C = [...
B(A(1,1), A(1, 2)), B(A(1,1), A(1,3)), B(A(1,2), A(1,3));...
B(A(2,1), A(2, 2)), B(A(2,1), A(2,3)), B(A(2,2), A(2,3));...
B(A(3,1), A(3, 2)), B(A(3,1), A(3,3)), B(A(3,2), A(3,3))
]
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!