Filter löschen
Filter löschen

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

17 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

madhan ravi
madhan ravi am 4 Mär. 2019

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by