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.
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!