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

6 次查看(过去 30 天)
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.

采纳的回答

madhan ravi
madhan ravi 2019-3-4

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by