Borrar filtros
Borrar filtros

Map values of a matrix as indices to get values from another matrix at those indices

17 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

madhan ravi
madhan ravi el 4 de Mzo. de 2019

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by