Map values of a matrix as indices to get values from another matrix at those indices
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Maxime Michel
el 4 de Mzo. de 2019
Respondida: madhan ravi
el 4 de Mzo. de 2019
I am currently trying to switch the values in a given matrix with the values in another matrix using the values of the first as indices for the second. Words won't be very helpful here so let me give an example.
A = [5, 4, 2, 6; 1, 5, 6, 2]; % A is a 2 by n matrix, here n is 4
B = [12, 15, 2, 9, 8, 6]'; % B is a column vector
What I would like to do is switch the values in A, using them as indices, with the values in B which would give the following:
C = [B(5), B(4), B(2), B(6); B(1), B(5), B(6), B(2)]; % This would give the below matrix
C = [8, 9, 15, 6; 12, 8, 9, 15];
I'm new to Matlab (using it only for educational reasons) so I have no clue if something exists or not.
0 comentarios
Respuesta aceptada
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!